#include using namespace std; typedef long long LL; const int nmax = 200010; const LL mod = 1000000007; int N,v[nmax],M; char ch[1000]; char x1,x2; int main(void){ LL i,j,urm,x,cnt,w,y1,y2,nr,nr2,ii; // freopen("txt.in","r",stdin); // freopen("txt.out","w",stdout); // ios::sync_with_stdio(false); cin >> N >> M; i = 1; while(cin >> ch){ int lg = strlen(ch); for(j = 1; j < lg-1; j+=2){ x1 = ch[j]; x2 = ch[j+1]; if(x1 == x2) continue; if(x1 >= 'A')y1 = (x1-'A')+10; else y1 = x1-'0'; if(x2 >= 'A')y2 = (x2-'A')+10; else y2 = x2-'0'; nr = y2+y1*16; int best = 100000; int ans = -1; for(ii = 0; ii <= 15; ++ii){ nr2 = ii+ii*16; if(abs(nr2-nr) < best){ best = abs(nr2-nr); ans = ii; } } if(ans <= 9) ch[j] = ans+'0'; else ch[j] = 'A'+(ans-10); } cout << "#"; for(j = 1; j < lg; j+=2) cout << ch[j]; if(i%M==0) cout << '\n'; else cout <<' '; ++i; } return 0; }