def set(x, y, f)
  f[y] ^= (1 << x)
end

def isset?(x, y, f)
  return (f[y] & (1 << x)) != 0
end

def shoot(x, y, f)
  set(x, y, f)
  set(x - 1, y, f) if x > 0
  set(x + 1, y, f) if x < 9
  set(x, y - 1, f) if y > 0
  set(x, y + 1, f) if y < 9
end

def count(x, y, f)
  c = 0
  c += 1 if isset?(x, y, f)
  c += 1 if x > 0 && isset?(x - 1, y, f)
  c += 1 if x < 9 && isset?(x + 1, y, f)
  c += 1 if y > 0 && isset?(x, y - 1, f)
  c += 1 if y < 9 && isset?(x, y + 1, f)
  return c
end

def check_shoot(f, ans)
  bits = 0
  f.each{|b| bits |= b}
  if bits == 0
    ans.each{|b| puts ("%010b" % b).reverse.split("").join(" ")}
    return true
  end

  counts = []
  for y in (0..9)
    for x in (0..9)
      if ! isset?(x, y, ans)
        c = count(x, y, f)
        counts.push [c, x, y] if c > 0
      end
    end
  end

  for cnt in counts.sort{|a, b| b[0] <=> a[0]}
    c, x, y = cnt

    shoot(x, y, f)
    set(x, y, ans)

    return true if check_shoot(f, ans)

    set(x, y, ans)
    shoot(x, y, f)
  end

  return false
end

### main

n = gets.strip.to_i

n.times.each do
  flds = []
  ans = []
  10.times.each do
    hl = gets.strip.gsub(/ /, '').reverse.to_i(2)
    flds.push hl
    ans.push 0
  end

  check_shoot(flds, ans)
end