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
	r=[]
	g=[]
	b=[]
	ac.each_with_index{|v,i|
		r=r.concat [an[i]] if v == "R"
		g=g.concat [an[i]] if v == "G"
		b=b.concat [an[i]] if v == "B"
	}
	maxRCount=0
	r.permutation{|pset|
		rCount=0
		(pset.length/3).times{|t|
			rCount += 1 if check(pset[3*t..3*t+2])
		}
		maxRCount = rCount if maxRCount < rCount
	}
	maxGCount=0
	g.permutation{|pset|
		gCount=0
		(pset.length/3).times{|t|
			gCount += 1 if check(pset[3*t..3*t+2])
		}
		maxGCount = gCount if maxGCount < gCount
	}
	maxBCount=0
	b.permutation{|pset|
		bCount=0
		(pset.length/3).times{|t|
			bCount += 1 if check(pset[3*t..3*t+2])
		}
		maxBCount = bCount if maxBCount < bCount
	}
	max = maxBCount + maxGCount + maxRCount
	p 1 if max >= 3
	p 0 if max < 3
}