#include <stdio.h>

int main(void)
{
	int card[3][9]={0};
	int tmp[9],ntmp;
	int kekka[100]={0};
	char mark;
	int n,i,j,k,l,m;
	int Rc=0,Gc=0,Bc=0,hantei;
	
	scanf("%d",&n);
	
	for(i=0;i<n;i++){
		for(j=0;j<9;j++){
			scanf("%d",&tmp[j]);
		}
		for(k=0;k<9;k++){
			scanf(" %c",&mark);
			switch(mark){
				case 'R' :
					card[0][Rc]=tmp[k];
					//printf("R%d ",card[0][Rc]);
					Rc++;
					break;
				case 'G' :
					card[1][Gc]=tmp[k];
					//printf("G%d ",card[1][Gc]);
					Gc++;
					break;
				case 'B' :
					card[2][Bc]=tmp[k];
					//printf("B%d ",card[2][Bc]);
					Bc++;
					break;
			}
			
		}
		
		for(m=0;m<3;m++){
		  for (j=0; j<9; ++j) {
		    for (k=j+1; k<9; ++k) {
		      if (card[m][j] > card[m][k]&&card[m][k]!=0) {
		        ntmp =  card[m][j];
		        card[m][j] = card[m][k];
		        card[m][k] = ntmp;
		      }
		    }
		  }
		}
		if(Rc%3==0&&Gc%3==0&&Bc%3==0){
			for(k=0;k<3;k++){
				for (j=0; j<9; j+=3) {
					if(((card[k][j]==card[k][j+1]-1)&&(card[k][j]==card[k][j+2]-2))||(card[k][j]==card[k][j+1])&&(card[k][j]==card[k][j+2])){
						/*????????¶????????£?????????????????°???????????????*/
						if(card[k][j]!=0||card[k][j+1]!=0||card[k][j+2]!=0) hantei++;;
						
					}
					
				}
				
			}
			if(hantei>=3){
				kekka[i]=1;
			}else if(hantei<3){
				kekka[i]=0;
			}
			hantei=0;
		}else{
			kekka[i]=0;
		}
	}

printf("\n");
for(i=0;i<n;i++){
	printf("%d\n",kekka[i]);
}



	
	return 0;
}

/*
???????????????????????? 9????????? 1???9 4?????????
?????????9??????????????????
???????????????1?????¨?????????1??????????????????
???1*3??????123???1?????????
???1*2???1???0?????????  ?????????????????¨??


?????????¨?????????
????????????§?????????%3??§????????????
?°?????????????????????????
??°????????????




*/