def isSequence?(x)
  return x[0] + 1 == x[1] && x[1] + 1 == x[2]
end

def isSameNumber?(x)
  return x[0] == x[1] && x[1] == x[2]
end

cl = {"R"=>0, "G"=>10,"B"=>100}
k = 9
t = gets.to_i
t.times do |i|
  n = gets.split.map(&:to_i)
  c = gets.split
  k.times do |j|
    n[j] += cl[c[j]]
  end
  n.sort!

  res = []
  3.times do |k|
    res << [n[k * 3], n[k * 3 + 1], n[k * 3 + 2]]
  end
  p (res.all?{|x| isSequence?(x) || isSameNumber?(x)}) ? 1: 0
end