object Main {
  val fld = Array.ofDim[Int](10)
  val ans = Array.ofDim[Int](10)

  def beam(y: Int, x: Int) = {
    val beams = 
      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)
    for(b <- beams) {
      fld(b._1) ^= (1 << b._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(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(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)
    }
  }