def win_state(arr)
  return false if arr.size % 3 != 0
  return true if arr.size == 0
  arr.permutation.to_a.any?{|k|
    k.each_slice(3).map{|a, b, c|
      (a.succ == c.pred && a.succ == b) || (a == c && a == b)
    }.all?
  }
end

t = gets.to_i
t.times do |i|
  n = gets.split.map(&:to_i)
  c = gets.split.map(&:to_s)
  r, g, b = [], [], []
  n.size.times do |j|
    r << n[j] if c[j] == "R"
    g << n[j] if c[j] == "G"
    b << n[j] if c[j] == "B"
  end
  res = [r, g, b].all?{|arr|
    win_state(arr)
  }
  p res ? 1 : 0
end