using System;

namespace AOJ.Volume1
{
    public class Puzzle
    {
        public static int Main()
        {
            int n = int.Parse(Console.ReadLine());
            for (int cnt = 1; cnt <= n; cnt++)
            {
                var puzzle = new int[9, 9];
                for (int i = 0; i < 9; i++)
                {
                    for (int j = 0; j < 9; j++) { puzzle[i, j] = 0; }
                }

                // ????????????????????????
                for (int i = 0; i < 9; i++)
                {
                    var line = Console.ReadLine().Trim().Split(' ');
                    for (int j = 0; j < 9; j++) { puzzle[i, j] = int.Parse(line[j]); }
                }

                var check = new bool[9, 9];
                // ??£?????¢????????§??????
                for (int i = 0; i < 3; i++)
                {
                    int st_h = 3 * i;
                    for (int j = 0; j < 3; j++)
                    {
                        int st_w = 3 * j;
                        var sq = new int[9];
                        sq[0] = puzzle[st_h, st_w];
                        sq[1] = puzzle[st_h, st_w + 1];
                        sq[2] = puzzle[st_h, st_w + 2];
                        sq[3] = puzzle[st_h + 1, st_w];
                        sq[4] = puzzle[st_h + 1, st_w + 1];
                        sq[5] = puzzle[st_h + 1, st_w + 2];
                        sq[6] = puzzle[st_h + 2, st_w];
                        sq[7] = puzzle[st_h + 2, st_w + 1];
                        sq[8] = puzzle[st_h + 2, st_w + 2];
                        var test = Count(sq);
                        check[st_h, st_w] = test[sq[0] - 1] != 1 ? false : true;
                        check[st_h, st_w + 1] = test[sq[1] - 1] != 1 ? false : true;
                        check[st_h, st_w + 2] = test[sq[2] - 1] != 1 ? false : true;
                        check[st_h + 1, st_w] = test[sq[3] - 1] != 1 ? false : true;
                        check[st_h + 1, st_w + 1] = test[sq[4] - 1] != 1 ? false : true;
                        check[st_h + 1, st_w + 2] = test[sq[5] - 1] != 1 ? false : true;
                        check[st_h + 2, st_w] = test[sq[6] - 1] != 1 ? false : true;
                        check[st_h + 2, st_w + 1] = test[sq[7] - 1] != 1 ? false : true;
                        check[st_h + 2, st_w + 2] = test[sq[8] - 1] != 1 ? false : true;
                    }
                }

                // ?¨?????????§??????
                for (int i = 0; i < 9; i++)
                {
                    var hori = new int[9];
                    for (int j = 0; j < 9; j++) { hori[j] = puzzle[i, j]; }
                    var test = Count(hori);
                    for (int j = 0; j < 9; j++)
                    {
                        if (test[puzzle[i, j] - 1] != 1) { check[i, j] = false; }
                    }
                }

                // ???????????§??????
                for (int i = 0; i < 9; i++)
                {
                    var ver = new int[9];
                    for (int j = 0; j < 9; j++) { ver[j] = puzzle[j, i]; }
                    var test = Count(ver);
                    for (int j = 0; j < 9; j++)
                    {
                        if (test[puzzle[j, i] - 1] != 1) { check[j, i] = false; }
                    }
                }

                // ??????
                for(int i = 0; i < 9; i++)
                {
                    string line = "";
                    for(int j = 0; j < 9; j++)
                    {
                        if (check[i, j]) { line += " " + puzzle[i, j]; }
                        else { line += "*" + puzzle[i, j]; }
                    }
                    Console.WriteLine(line);
                }
                // ?????????????????????????????????????????????
                if (cnt < n) { Console.WriteLine(""); }
            }
            return 0;
        }

        // ??°?????????????????°?????????
        // ???????????????ret[0]???'1'??????????????°
        private static int[] Count(int[] chk)
        {
            var ret = new int[9];
            for (int i = 0; i < 9; i++) { ret[chk[i] - 1]++; }

            return ret;
        }
    }
}

Measured memory_bytes: 9356