class Field (var value: List[Int]) {
    def get: List[Int] = {
        this.value
    }
    def update(y: Int, x: Int): Unit = {
        val bits = this.value(y) ^ (1 << x)
        this.value = (0 to 9).toList.map(i => if(i == y) bits else this.value(i))
    }
    def init(fld:List[Int]): Unit = {
        this.value = fld
    }
}
object Main {
    var fld = new Field(List(1))
    def main(args:Array[String]) = {
        val sc = new java.util.Scanner(System.in)
        val n = sc.nextInt
        sc.nextLine
        for(i <- 1 to n) {
            val orig = (1 to 10).toList.map(_ => Integer.parseInt(sc.nextLine.split(" ").mkString("").reverse, 2))
            fld = new Field(orig)
            var i = 0
            var flag = true
            var ans = List(1)
            while(flag) {
                fld.init(orig)
                ans = total_flip(i, 0, Nil)
                if(fld.get(9) == 0) {
                    ans.foreach(bits => println(Integer.toBinaryString(bits).reverse.padTo(10, '0').split("").mkString(" ")))
                    flag = false
                }
                else i += 1
            }
        }
    }
    def beam(y: Int, x: Int): Unit = {
        val dir = List((y, x), (y - 1, x), (y, x - 1), (y + 1, x), (y, x + 1)).filter(p => 0 <= p._1 && p._1 < 10 && 0 <= p._2 && p._2 < 10)
        dir.foreach(p => fld.update(p._1, p._2))
    }

    def row_flip(y: Int, x: Int, bits: Int, acc: Int): Int = {
        if(x == 10) acc
        else {
            if((bits & (1 << x)) != 0) {
                beam(y, x)
                row_flip(y, x + 1, bits, acc + (1 << x))
            }
            else row_flip(y, x + 1, bits, acc)
        }
    }

    def total_flip(bits: Int, y: Int, ans: List[Int]): List[Int] = {
        if(y == 10) ans
        else if(y == 0) total_flip(bits, y + 1, List(row_flip(0, 0, bits, 0)))
        else total_flip(bits, y + 1, ans ::: List(row_flip(y, 0, fld.get(y-1), 0)))
    }
}