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


# ????????????????????????????????????????????????????????????????????? 
def permutation(_x)
  @res = []
  m = []
  _x.uniq.map{|i| m << _x.count(i)}
  x = _x.uniq
  def perm(x, m, result=[])
    if m.all?{|n| n == 0 }
      @res << result
    else
      (m.length).times{|i|
        if m[i] > 0
          m[i] -= 1
          perm(x, m, result+[x[i]])
          m[i] += 1
        end
      }
    end
  end
  perm(x, m)
  return @res
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!


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