import scala.math._

object Main {
  val sc = new java.util.Scanner(System.in)
  def change(a: Array[Array[Int]], x: Int, y: Int) {
    val dx = Seq(0, -1, 0, 1, 0)
    val dy = Seq(0, 0, 1, 0, -1)
    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]]): Option[Array[Array[Int]]] = {
    val test = (n: Int) => {
      val b = a.map(_.clone)
      val c = Array.ofDim[Int](10,10)
      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
          }
        }
      }
      if (b.map(_.sum).sum == 0) {
        Some(c)
      } else {
        None
      }
    }
    for(i <- 0 until (1<<10)) {
      test(i) match {
        case Some(c) => return Some(c)
        case _ => 
      }
    }
    return None
  }
  def main(args: Array[String]) {
    val n = sc.nextInt()
    sc.nextLine()
    for(_ <- 1 to n) {
      val a = (for(_ <- 1 to 10) yield sc.nextLine().split(" ").map(_.toInt).toArray).toArray
      solve(a).get.foreach(s => println(s.mkString(" ")))
    }
  }
}