#include <bits/stdc++.h> using namespace std; using uint = unsigned int; using ll = long long; using pii = pair<int, int>; #define dbg(x) cerr<<#x": "<<(x)<<'\n' #define dbg_v(x, n) cerr<<#x"[]: ";for(long long _=0;_<n;++_)cerr<<(x)[_]<<' ';cerr<<'\n' #define all(v) v.begin(), v.end() #define NMAX char get(char c1, char c2) { int c, cmin, a, b, x, d; a = ('A' <= c1 && c1 <= 'Z' ? c1 - 'A' + 10 : c1 - '0'); b = ('A' <= c2 && c2 <= 'Z' ? c2 - 'A' + 10 : c2 - '0'); x = 16 * a + b; d = 1000000; for(c = 0; c <= 15; ++c) if(abs(x - 16 * c - c) < d) cmin = c, d = abs(x - 16 * c - c); return (cmin < 10 ? '0' + cmin : 'A' + cmin - 10); } int main() { #ifndef ONLINE_JUDGE ifstream cin("data.in"); ofstream cout("data.out"); #endif ios_base::sync_with_stdio(false); int i, j, k, m, n; char s[10]; cin >> m >> n; for(i = 0; i < m; ++i, cout << '\n') for(j = 0; j < n; ++j) { cin >> s; cout << '#'; for(k = 1; k < 6; k += 2) cout << get(s[k], s[k + 1]); cout << ' '; } return 0; }