def check v
	return true if (v&v).count == 1
	return true if v[0]+1==v[1] && v[1]+1==v[2]
	return false
end

gets.to_i.times{
	an=gets.split(" ").map{|e|e.to_i}
	ac=gets.split(" ")
	count=0
	c=[[],[],[]]
	ac.each_with_index{|v,i|
		c[0].concat [an[i]] if v == "R"
		c[1].concat [an[i]] if v == "G"
		c[2].concat [an[i]] if v == "B"
	}
	max=0
	3.times{|i|
		maxCount=0
		c[i].permutation{|pset|
			count=0
			(pset.length/3).times{|t|
				break if !check(pset[3*t..3*t+2])
				count += 1
			}
			maxCount = count if maxCount < count
			break if max+maxCount >= 3
		}
		max += maxCount
		break if max >= 3
	}
	p 1 if max >= 3
	p 0 if max < 3
}