#include <bits/stdc++.h>
using namespace std;
#define MAX 101
int N, xx[4] = {0, 1, 0, -1}, yy[4] = {1, 0, -1, 0}, K, ct;
int chess[MAX][11], flag[MAX][11], f;
void dfs(int x, int y, int num)
{
flag[x][y] = 1;
for (int i = 0; i <= 3; i++)
{
int nx = x + xx[i];
int ny = y + yy[i];
if (flag[nx][ny] == 0 && chess[nx][ny] == num)
{
ct++;
dfs(nx, ny, num);
}
}
}
void change(){
for (int i = 1; i <= N; i++)
{
for (int j = 1; j < 11; j++)
{
if (flag[i][j])
{
chess[i][j] = 0;
}
}
}
}
void fall(){
for (int i = N; i >= 1; i--)
{
for (int j = 1; j <= 10; j++)
{
if (chess[i][j] != 0)
{
int pos = i;
while (chess[pos + 1][j] == 0 && pos <= N)
{
pos++;
}
if (pos != i)
{
chess[pos][j] = chess[i][j];
chess[i][j] = 0;
}
}
}
}
}
int main(int argc, char const *argv[])
{
cin>>N>>K;
for (int i = 1; i <= N; i++)
{
for (int j = 1; j < 11; j++)
{
scanf("%1d", &chess[i][j]);
}
}
f = 1;
while (f)
{
f = 0;
for (int i = 1; i <= N; i++)
{
for (int j = 1; i < 11; i++)
{
if (chess[i][j] != 0)
{
ct = 1;
memset(flag, 0, sizeof(flag));
dfs(i, j, chess[i][j]);
if (ct >= K)
{
change();
f = 1;
}
}
}
}
if (f)
{
fall();
}
}
for (int i = 1; i <= N; i++)
{
for (int j = 1; j < 11; j++)
{
cout << chess[i][j];
}
cout<<endl;
}
return 0;
}