#include int toint(char ch){ if(ch >= 'A'){ return ((int)(ch - 'A') + 10); }else{ return ((int)(ch - '0')); } } int abss(int x){ if(x < 0) return x * (-1); return x; } char tocrr(int i){ if(i > 9) return ((char)('A' + i - 10)); else return ((char)('0' + i)); } int main(){ //freopen("file", "r", stdin); int N, M; scanf("%d %d", &N, &M); int V[1000]; for(int i = 0; i < 16; ++i){ V[i] = i * 16 + i * 16; } char line[1000]; for(int i = 0; i < N; ++i){ for(int j = 0; j < M; ++j){ scanf("%s", line); printf("#"); int x, y; int n1, n2, n3; x = toint(line[1]); y = toint(line[2]); n1 = x * 16 + y * 16; x = toint(line[3]); y = toint(line[4]); n2 = x * 16 + y * 16; x = toint(line[5]); y = toint(line[6]); n3 = x * 16 + y * 16; int dd = 55555, p1, p2, p3; for(int c1 = 0; c1 < 16; ++c1){ int v1 = abss(V[c1] - n1); for(int c2 = 0; c2 < 16; ++c2){ int v2 = abss(V[c2] - n2); for(int c3 = 0; c3 < 16; ++c3){ int v3 = abss(V[c3] - n3); int vv = v1 + v2 + v3; if(vv < dd){ dd = vv; p1 = c1; p2 = c2; p3 = c3; } } } } printf("%c%c%c ", tocrr(p1), tocrr(p2), tocrr(p3)); } printf("\n"); } return 0; }