object Main {
    val fld = Array.ofDim[Int](10)
    val ans = Array.ofDim[Int](10)
    val my = List(0, -1,  0, 1, 0)
    val mx = List(0,  0, -1, 0, 1)
    def beam(y: Int, x: Int) = {
        val target = my.zip(mx).map(mv => (mv._1 + y, mv._2 + x))
            .filter(p => 0 <= p._1 && p._1 < 10 && 0 <= p._2 && p._2 < 10)
        for(p <- target) {
            fld(p._1) ^= (1 << p._2)
        }
    }

    def init(orig: Array[Int]) = {
        for(y <- 0 to 9) {
            fld(y) = orig(y)
            ans(y) = 0
        }
    }

    def row_flip(y: Int, bits: Int) = {
        for(x <- 0 to 9) {
            if((bits & (1 << x)) != 0) {
                beam(y, x)
                ans(y) |= (1 << x)
            }
        }
    }

    def flip(y: Int, bits: Int) = {
        row_flip(0, bits)
        for(y <- 1 to 9) row_flip(y, fld(y - 1))
    }

    def solve(orig: Array[Int]) = {
        var i = 0
        var flag = true
        while(flag) {
            init(orig)
            flip(0, i)
            if(fld(9) == 0) {
                ans.foreach(bits => 
                    println(Integer.toBinaryString(bits).reverse.padTo(10, '0')
                            .split("").mkString(" ")))
                flag = false
            }
            else i += 1
        }
    }

    def main(args:Array[String]) = {
        val sc = new java.util.Scanner(System.in)
        val n = sc.nextInt
        sc.nextLine
        for(_ <- 1 to n) {
            val orig = (1 to 10).toArray.map(_ => 
                Integer.parseInt(sc.nextLine.split(" ").mkString("").reverse, 2))
            solve(orig)
        }
    }
}