
object Main extends App {
  import scala.io.StdIn.{readLine}
  for (testCase← 0 until readLine().toInt){
    val field = Field()
    for (y ← 0 until 10){
      readLine().split(' ').map(_.toInt).zipWithIndex.foreach{
        case (0, x) ⇒ field(x, y) = Off
        case (1, x) ⇒ field(x, y) = On
      }
    }
    val raw = Field()
    (0 until 1024).flatMap(canResetField(field, _)).flatten.flatten.foreach(c ⇒ raw(c) = On)
    println((0 until 10).map(y ⇒ (0 until 10).map(x ⇒ raw(x, y) match {case Off ⇒ 0 case On ⇒ 1}).mkString(""," ","\n")).mkString)
  }
  case class Coordinate(x:Int, y:Int){
    def +(that:Coordinate):Coordinate = Coordinate(x + that.x, y + that.y)
  }
  def BeamLine(initial:Int):Iterable[Coordinate] = (0 until 10).filter{x ⇒ ((1 << x) & initial) != 0}.map{Coordinate(_, 0)}
  sealed trait Lamp{
    def switch:Lamp
  }
  object On extends Lamp{
    override def switch:Lamp = Off
  }
  object Off extends Lamp{
    override def switch:Lamp = On
  }
  object Field{
    def apply():Field = new Field()
    private val relationalEffectArea:Iterable[Coordinate] = Coordinate(0, -1)::Coordinate(-1, 0)::Coordinate(0, 0)::Coordinate(1, 0)::Coordinate(0, 1)::Nil
  }
  class Field{
    private val mArray:Array[Array[Lamp]]= Array.tabulate(10){_ ⇒ Array.tabulate(10){_ ⇒ Off}}
    def apply(x:Int, y:Int):Lamp = mArray(x)(y)
    def apply(coordinate: Coordinate):Lamp = mArray(coordinate.x)(coordinate.y)
    def update(x:Int, y:Int, value:Lamp):Unit = mArray(x)(y) = value
    def update(coordinate: Coordinate, value:Lamp):Unit = mArray(coordinate.x)(coordinate.y) = value
    def shootBeam(beam:Coordinate):Unit = Field.relationalEffectArea.map{_ + beam}.filter{case Coordinate(x, y) ⇒ (0 until 10).contains(x) && (0 until 10).contains(y)}.foreach{case Coordinate(x, y) ⇒ mArray(x)(y) = mArray(x)(y).switch}
  }
  def canResetField(field: Field, initial:Int):Option[Iterable[Iterable[Coordinate]]] = {
    var res:List[Iterable[Coordinate]] = BeamLine(initial)::Nil
    res.foreach{_.foreach{field.shootBeam(_)}}
    for (y ← 1 until 10){
      val l = (0 until 10).filter{field(_, y - 1) == On}.map{Coordinate(_, y)}
      l.foreach{field.shootBeam(_)}
      res = l::res
    }
    (0 until 10).forall{field(_, 9) == Off} match{
      case true ⇒ {
        res.foreach(_.foreach(c ⇒ field.shootBeam(c)))
        Some(res)
      }
      case false ⇒ {
        res.foreach(_.foreach(c ⇒ field.shootBeam(c)))
        None
      }
    }
  }
}

