t = gets.to_i
t.times do |i|
  res = 1
  n = gets.split.map(&:to_i)
  c = gets.split.map(&:to_s)
  if (c.count("R") % 3 + c.count("G") % 3 + c.count("G") % 3 != 0)
    res = 0
  else
    m = [n, c].transpose.sort_by{|x| [x[0], x[1]]}
    m.transpose[0].each_slice(3) do |d, e, f|
      if d.succ != f.pred && d != f
        res = 0
        break
      end
    end
  end
  p res
end