class Board:
    def __init__(self):
        self.b = []
        for i in range(9):
            self.b.append([0 for j in range(9)])

    def __available(self, x, y):
        result = []
        for i in range(1, 10):
            avail = True
            
            for m in range(9):
                if self.b[x][m] == i or self.b[m][y] == i:
                    avail = False
                    # break

            if avail:
                mm = (x / 3) * 3
                nn = (y / 3) * 3
                for m in range(mm, mm + 3):
                    for n in range(nn, nn + 3):
                        if self.b[m][n] == i:
                            avail = False
                            # break

            if avail:
                result.append(i)

        return result

    def find(self, x = 0, y = 0, depth = 0):
        if depth == 81:
            yield str(self)
            return

        r = self.__available(x, y)
        if len(r) == 0:
            return

        nextx = x
        nexty = y + 1
        if nexty == 9:
            nextx += 1
            nexty = 0

        for a in r:
            self.b[x][y] = a
            for s in self.find( nextx, nexty, depth + 1):
                yield s
            self.b[x][y] = 0

    def __str__(self):
        return '\n'.join(str(s) for s in self.b)
        
a = Board()
for ans in a.find():
    print ans
    raw_input()


