#include<stdio.h>
int main(){
  int n,i,j,a[20];
  char b[20],c[20]={"RGB"};
  scanf("%d",&n);
  while(n--){
    int d[20][20]={0};
    for(i=0;i<9;i++)scanf("%d" ,&a[i]);
    for(i=0;i<9;i++)scanf(" %c",&b[i]);
    for(i=0;i<9;i++){
      for(j=0;b[i]-c[j];j++);
      d[a[i]][j]++;
    }
    for(j=0;j<3;j++){
      for(i=0;i<9;i++){
	if(d[i][j]>2)d[i][j]-=3;
	if(d[i][j]>0){
	  if(d[i+1][j]<d[i][j]||d[i+2][j]<d[i][j])break;
	  d[i+1][j]-=d[i][j];
	  d[i+2][j]-=d[i][j];
	}
      }
      if(i-9)break; 
    }
    printf("%d\n",j-3?0:1);
  }
  return 0;
}