#include<stdio.h>
#include<stdlib.h>
#include<string.h>

struct data{
    int n;
    int c;
};

int main(){

    int t;
    int i,j,s; 
    int ch;   
    int x,y,z;
    char w;
    int count;
    
    struct data card[50][9];    
	struct data tmp;

    scanf("%d",&t);
    
    for(i=0;i<t;i++){
        for(j=0;j<9;j++){
            scanf("%d ",&card[i][j].n);
        }
        for(j=0;j<9;j++){
            scanf("%c ",&w);
            if(w=='R') card[i][j].c=10;
            if(w=='G') card[i][j].c=20;
            if(w=='B') card[i][j].c=30;
        }
    }
    for(i=0;i<t;i++){
        x=0;y=0;z=0;
		count = 0;
        for(j=0;j<9;j++){
            if(card[i][j].c==10) x++;
            else if(card[i][j].c==20) y++;
            else if(card[i][j].c==30) z++;
        }
        if(x%3!=0 || y%3!=0 || z%3!=0){
            printf("0\n");
        }
        else{
        	for(j=0;j<9;j++){
        		for(s=0;s<9-j-1;s++){
        			if(card[i][s].c>card[i][s+1].c){
        				tmp=card[i][s];
        				card[i][s]=card[i][s+1];
        				card[i][s+1]=tmp;
        			}
        		}
        	}
        	
        	
        	for(j=0;j<9;j++){
        		for(s=0;s<9-j-1;s++){
        			if(card[i][s].n>card[i][s+1].n && card[i][s].c==card[i][s+1].c){
        				tmp=card[i][s];
        				card[i][s]=card[i][s+1];
        				card[i][s+1]=tmp;
        			}
        		}
        	}
        	
        		if(((card[i][0].n+2)==(card[i][1].n+1) && (card[i][1].n+2)==(card[i][2].n+1)) || ((card[i][0].n)==(card[i][1].n) && (card[i][1].n)==(card[i][2].n))) {
        			count++;
        		
        		}
        		if(((card[i][3].n+2)==(card[i][4].n+1) && (card[i][4].n+2)==(card[i][5].n+1)) || ((card[i][3].n)==(card[i][4].n) && (card[i][4].n)==(card[i][5].n))){ 
        		
        			count++;
        		}
        		if(((card[i][6].n+2)==(card[i][7].n+1) && (card[i][7].n+2)==(card[i][8].n+1)) || ((card[i][6].n)==(card[i][7].n) && (card[i][7].n)==(card[i][8].n))) {
        			count++;
    			}	
        	
        	if(count==3) printf("1\n");
        	else printf("0\n");
        	
 
        }
        
    }
    
            

return 0;
}