import scala.math._

object Main {
  val sc = new java.util.Scanner(System.in)
  val dx = Seq(0, -1, 0, 1, 0)
  val dy = Seq(0, 0, 1, 0, -1)
  val b = Array.ofDim[Int](10, 10)
  val c = Array.ofDim[Int](10, 10)
  val change = (a: Array[Array[Int]], x: Int, y: Int) => {
    for {
      d <- dx.zip(dy)
      xi = x + d._1
      yi = y + d._2
      if 0 <= xi
      if xi < 10
      if 0 <= yi
      if yi < 10
    } {
      a(xi)(yi) = (a(xi)(yi)+1)%2
    }
  }
  def solve(a: Array[Array[Int]]): Array[Array[Int]] = {
    val test = (n: Int) => {
      for(i <- 0 until 10; j <- 0 until 10) {
        b(i)(j) = a(i)(j)
        c(i)(j) = 0
      }
      for(i <- 0 until 10) {
        if((n & (1 << i)) != 0) {
          change(b, 0, i)
          c(0)(i) = 1
        }
      }
      for(i <- 1 until 10) {
        for(j <- 0 until 10) {
          if(b(i-1)(j) == 1) {
            change(b, i, j)
            c(i)(j) = 1
          }
        }
      }
      b.map(_.sum).sum == 0
    }
    var i = 0
    while(i < (1 << 10)) {
      if(test(i)) {
        return c
      }
      i += 1
    }
    return c
  }
  def main(args: Array[String]) {
    val n = sc.nextInt()
    val a = Array.ofDim[Int](10, 10)
    for(_ <- 1 to n) {
      for(i <- 0 until 10; j <- 0 until 10) {
        a(i)(j) = sc.nextInt
      }
      solve(a).foreach(s => println(s.mkString(" ")))
    }
  }
}