#include <iostream>
#include <algorithm>
#include <string>

using namespace std;

int trans (char c)
{
    if ('0' <= c && c <= '9') return c - 48;
    return c - 'A' + 10;
}

char tr (int x)
{
    if (0 <= x && x <= 9) return x + 48;
    return x + 'A' - 10;
}

int dif (string a, string b)
{
    int x = trans (a[0]);
    int y = trans (a[1]);
    int z = trans (b[0]);
    int t = trans (b[1]);

    x = x * 16 + y;
    z = z * 16 + t;

    return max (x - z, z - x);
}

string ss, str, ns;

int main ()
{
   // ifstream cin ("file.in");
   // ofstream cout ("file.out");

    int n, m;
    cin >> n >> m;

    for (int i = 1; i <= n; ++i)
    {
        for (int j = 1; j <= m; ++j)
        {
            cin >> ss;

            cout << "#";
            for (int k = 1; k < ss.size (); k += 2)
            {
                str = ss.substr (k, 2);

                int mi = 20000000, poz;
                for (int h = 0; h < 16; ++h)
                {
                    char c = tr (h);
                    ns.clear ();
                    ns += c;
                    ns += c;

                    int x = dif (ns, str);
                    if (x < mi) mi = x, poz = h;
                }

                cout << tr (poz);
            }

            cout << " " ;
        }
        cout << '\n';
    }

    return 0;
}