gets.to_i.times do
  n = gets.split.map(&:to_i)
  c = gets.split
  color = {}
  color["R"] = [0]*9
  color["G"] = [0]*9
  color["B"] = [0]*9
  9.times{ |i| color[c[i]][n[i]-1] += 1 }
  ret = 0
  ["R", "G", "B"].each do |s|
    7.times do |i|
      if color[s][i,3].all?{ |v| v >= 1 }
        while color[s][i,3].all?{ |v| v >= 1 }
          3.times{ |j| color[s][i+j] -= 1}
          ret += 1
        end
      end
    end
    9.times do |i|
      if color[s][i] >= 3
        ret += color[s][i] / 3
      end
    end
  end
  if ret == 3 then puts 1
  else puts 0
  end
end