Despite YY’s so much homework, she would like to take some time to play with her minions first.

YY lines her minions up to an N*M matrix. Every minion has two statuses: awake or asleep. We use 0(the digit) to represent that it is asleep, and 1 for awake. Also, we define the minions who are around a minion closest in one of the eight directions its neighbors. And every minute every minion will change its status by the following specific rules:

If this minion is awake, and the number of its neighbors who are awake is less than 2, this minion will feel lonely and turn to asleep.

If this minion is awake, and the number of its neighbors who are awake is more than 3, this minion will turn to asleep for it will feel too crowded.

If this minion is awake, and the number of its neighbors who are awake is exactly 2 or 3, this minion will keep being awake and feel very happy.

If this minion is asleep, and the number of its neighbors who are awake is exactly 3, this minion will wake up because of the noise.

Note that all changes take place at the same time at the beginning of a specific minute.

Also, some minions will get bored and leave this silly game. We use ‘X’s to describe them. We suppose that a minion would leave after T minutes. It will leave at the end of the Tth minute. Its status is considered during the change at the beginning of the Tth minute, and should be ignored after that. Of course, one minion will not leave twice!

YY is a girl full of curiosity and wants to know every minion’s status after F minutes. But you know she is weak and lazy! Please help this cute girl to solve this problem :)