#define R(i,n)for(i=0;i<n;i++)
int N,i,j,k,f,n[9];char h;int main(){scanf("%d",&N);R(i,N){int c[3][12]={{0}};f=1;R(j,9){scanf("%d",&n[j]);}R(j,9){scanf(" %c",&h);c[h=='R'?0:h=='G'?1:2][n[j]-1]++;}R(j,3){R(k,12){f&=c[j][k]>=0;c[j][k]%=3;if(k<9){c[j][k+2]-=c[j][k];c[j][k+1]-=c[j][k];}}}printf("%d\n",f);}exit(0);}