import java.util.*

fun main(args:Array<String>):Unit {
    val r = Array(10){0}
    val g = Array(10){0}
    val b = Array(10){0}
    repeat(readLine()!!.toInt()){
        readLine()!!.split(' ').map(String::toInt).zip(readLine()!!.split(' ')).forEach { (i, c) ->
            when(c){
                "R" -> r[i]++
                "G" -> g[i]++
                else -> b[i]++
            }
        }
        println(if (isSet(r) && isSet(g) && isSet(b)) 1 else 0)
        r.fill(0)
        g.fill(0)
        b.fill(0)
    }
}
fun isSet(array:Array<Int>):Boolean {
    for (i in 0 until 10){
        if (array[i] < 0){
            return false
        }else if (array[i] > 0){
            if (i < 8){
                (i .. (i + 2)).forEach{
                    array[it] -= 1
                }
                if (isSet(array)) return true
                (i .. (i + 2)).forEach {
                    array[it] += 1
                }
            }
            array[i] -= 3
            if (isSet(array)) return true
            array[i] += 3
            return false
        }
    }
    return true
}
