a = []
M = int(input())
for i in range(M*2):
    if(i%2==0):
        a.append(map(int, input().split()))
    else:
        a.append(map(str, input().split()))

for i in range(M):
    #data = [[2,2,2,3,3,3,1,1,1],["R","G","B","R","G","B","R","G","B"]]
    data = a[i*2:(i+1)*2]
    data_df = pd.DataFrame(data)
    data_df = data_df.sort_values(1,axis=1)
    #print(i)
    #print(data_df,"\n")
    rgb_count = 0
    for j in range(3):
        data3 = data_df.iloc[:,3*j:3*(j+1)].sort_values(0,axis=1)
        r = (data3.iloc[:,0][0]+data3.iloc[:,2][0])/data3.iloc[:,1][0]
        if data3.iloc[:,0][1] == data3.iloc[:,1][1] == data3.iloc[:,2][1]:
            rgb_count+=1
        #print(data3.iloc[:,0][1])
        #print("1 = ",data3.iloc[:,1][1])
        #print("2 = ",data3.iloc[:,2][1])
        #print(data3)
        #print("r = ",r)
        
    
    if(r == 2 and rgb_count == 3):#連番または同じ値　かつ　同じ色
        print("1")
    elif(data_df.iloc[:,0][0] != 8 and data_df.iloc[:,1][0] != 9 and data_df.iloc[:,3][0] != 1):
        print("0")
    else:
        print("0")



### FIXED CODE ###

T = int(input())
for i in range(T):
    n = [int(i) for i in input().split()]
    c = [i for i in input().split()]
    value = [[],[],[]]
    for j in range(9):
        if c[j] == "R":
            value[0].append(n[j])
        elif c[j] == "G":
            value[1].append(n[j])
        else:
            value[2].append(n[j])
    ans = 1
    for i in range(3):
        l = len(value[i])
        if l%3 != 0:#RGBの長さが3の倍数でないと、正解になる可能性はない
            ans = 0
        else:
            value[i].sort()
            s = l//3
            j=0
            while ans>0 and s>0 and j<len(value[i])-2:
                if value[i][j] == value[i][j+1]:#隣り合う数字が一致している場合
                    if value[i][j+1] == value[i][j+2]:#3連続で同じ数字が並んでいる場合
                        for k in range(3):
                            value[i].pop(j)#値の削除
                        s-=1
                    elif value[i][j+1]+1==value[i][j+2]:#2つめの数字と3つ目の数字が連番　ex)112,223,334,
                        k=j+3
                        while k<len(value[i]) and value[i][k]==value[i][j+2]:#3つめと4つめの値が同じ
                            k+=1
                        if k>=len(value[i]) or value[i][k]!=value[i][j+2]+1:#4つ目と5つ目の数字が連番でない場合 ex)11225,22335　不正解
                            ans=0
                        else:
                            #値削除
                            value[i].pop(k)
                            value[i].pop(j+2)
                            value[i].pop(j)
                        s-=1
                    else:#3つ目の数字が全然違うやつ
                        ans=0

                elif value[i][j]+1==value[i][j+1]:#隣り合う数字が連番の場合
                    k=j+2
                    while k<len(value[i]) and value[i][k]==value[i][j+1]:
                        k+=1
                    if k>=len(value[i]) or value[i][k]!=value[i][j+1]+1:#3つめの数字が連番でない場合　不正解
                        ans=0
                    else:
                        #値削除
                        value[i].pop(k)
                        value[i].pop(j+1)
                        value[i].pop(j)
                        s-=1
                else:#隣り合う数字が連番でもなく、同値でもない場合　不正解
                    ans=0
        i+=1
    print(ans)