#include <iostream>
#include <fstream>
#include <algorithm>
using namespace std;
fstream fin("compress.in");
string image[64]; int W,T;
void compress(int xStart, int xEnd, int yStart, int yEnd) {
int ones = 0;
for (int x=xStart; x < xEnd; x++)
for (int y=yStart; y< yEnd; y++)
if (image[y][x] == '1')
ones++;
int total = (xEnd-xStart)*(yEnd-yStart);
int majority = max(ones, total-ones);
if (majority*100 >= T * total) {
char charval = (ones > total-ones) ? '1' : '0';
for (int x=xStart; x < xEnd; x++)
for (int y=yStart; y< yEnd; y++)
image[y][x] = charval;
} else {
int xMid = (xStart + xEnd) / 2;
int yMid = (yStart + yEnd) / 2;
compress(xMid, xEnd, yStart, yMid); compress(xStart, xMid, yStart, yMid); compress(xStart, xMid, yMid, yEnd); compress(xMid, xEnd, yMid, yEnd); }
}
int main() {
int count=0;
fin >> W;
while (W > 0) {
count++;
fin >> T;
for (int i=0; i<W; i++)
fin >> image[i];
compress(0, W, 0, W);
cout << "Image " << count << ":" << endl;
for (int i=0; i<W; i++)
cout << image[i] << endl;
fin >> W;
}
}