object Main {
    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 fld = (1 to 10).toList.map(_ => Integer.parseInt(sc.nextLine.split(" ").mkString("").reverse, 2))
            for(bits <- 0 to (1 << 10) - 1) {
                val list = solve(bits, 0, Nil, fld)
                if(list.size != 0) list.foreach(bits => println(Integer.toBinaryString(bits).reverse.padTo(10, '0').split("").mkString(" ")))
            }
        }
    }

    def beam(y: Int, x: Int, fld: List[Int]): List[Int] = {
        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.foldLeft(fld)((acc, p) => flip(acc, p._1, p._2) )
    }

    def flip(fld: List[Int], y: Int, x: Int): List[Int] = {
        val bits = fld(y) ^ (1 << x)
        (0 to 9).toList.map((i) => if(i == y) bits else fld(i))
    }

    def to_zero_all_one_line(y: Int, x: Int, bits: Int, acc: Int, fld: List[Int]): (Int, List[Int]) = {
        if(x == 10) (acc, fld)
        else {
            if((bits & (1 << x)) != 0) to_zero_all_one_line(y, x + 1, bits, acc + (1 << x), beam(y, x, fld))
            else to_zero_all_one_line(y, x + 1, bits, acc, fld)
        }
    }

    def solve(bits: Int, y: Int, ans: List[Int], fld: List[Int]): List[Int] = {
        if(y == 0) {
            val ret = to_zero_all_one_line(0, 0, bits, 0, fld)
            solve(bits, y + 1, List(ret._1), ret._2)
        }
        else if(y == 10) if(fld(9) == 0) ans else List()
        else {
            val ret = to_zero_all_one_line(y, 0, fld(y-1), 0, fld)
            solve(bits, y + 1, ans ::: List(ret._1), ret._2)
        }
    }
}