
int n;
int n_cd[3][9];
int n_cl[3];
int n_set;
int check();
void rm_sets();
int rm_id_sets(int, int);
int rm_seq_sets(int);

void dbg(){
	int i,j;
	for(i = 0; i < 3; i++){
		printf("------n_cl[%d]: %d\n", i, n_cl[i]);
		for(j = 0; j < 9; j++){
			printf("n_cd[%d][%d]: %d\n", i, j, n_cd[i][j]);
		}
	}
}

int main(){
	int i,j;
	char c;
	int cd_in[9], cl_in[i];
	
	scanf("%d", &n);
	while(n--){
		//input
		for(i = 0; i < 9; i++) scanf("%d",&cd_in[i]);
		for(i = 0; i < 9; i++){
			cd_in[i]--;
			scanf(" %c", &c);
			if(c == 'R') cl_in[i] = 0;
			else if(c == 'G') cl_in[i] = 1;
			else cl_in[i] = 2;
		}
		//init
		for(j = 0; j < 3; j++){
			n_cl[j] = 0;
			for(i = 0; i < 9; i++)n_cd[j][i] = 0;
		}
		for(i = 0; i < 9; i++){n_cd[ cl_in[i] ][ cd_in[i] ]++; n_cl[ cl_in[i] ]++;}
			
		//check
			//rm_seq_sets(2);
			//dbg();
		printf("%d\n", check());
	}
	
	return 0;
}
	
int check(){
	int result;
	int i,j,k,l;
	int bkup_n_cd[3][10], bkup_n_cl[3], bkup_n_set;
	n_set = 0;
	int trp_list[3];
	int n_trp;
	for(i = 0; i < 3; i++){
		if(n_cl[i] == 0){;
		}else if(n_cl[i] == 3 || n_cl[i] == 6){rm_sets(i);
		}else if(n_cl[i] == 9){
			//listup triplication
			n_trp = 0;
			for(j = 0; j < 9; j++){
				if(n_cd[i][j] >= 3){trp_list[n_trp++] = j;}
			}
			//backup
			for(j = 0; j < 3; j++){
				bkup_n_cl[j] = n_cl[j];
				for(k = 0; k < 9; k++){
					bkup_n_cd[j][k] = n_cd[j][k];
				}
			}
			bkup_n_set = n_set;
			if(n_trp == 0){
				rm_sets(i);
				break;
			}
			//try to remove triplication
			for(j = 0; j < n_trp; j++){
				//recover
				for(k = 0; k < 3; k++){
					n_cl[k] = bkup_n_cl[k];
					for(l = 0; l < 9 ; l++){
						bkup_n_cd[k][l] = n_cd[k][l];
					}
				}
				rm_id_sets(i, trp_list[j]);
				rm_sets(i);
				if( n_set == 3) break;
			}
		}else{
			//falure
			break;
		}
	}
	result = (n_set == 3)?1:0;
	return result;
}

int rm_id_sets(int cl,  int num){
	int i, flag = 0;
	if(num = -1){
		for(i = 0; i < 9; i++){
			if(n_cd[cl][i] >= 3){
				n_cd[cl][i] -= 3;
				n_set++;
				flag = 1;
			}
		}
	}else{
		if(n_cd[cl][num] >= 3){
			n_cd[cl][num] -= 3;
			n_set++;
			flag = 1;
		}
	}
	return flag;
}
int rm_seq_sets(int cl){
	int i, flag = 0;
	for(i = 0; i < 7; i++){
		if(n_cd[cl][i] >= 1 && n_cd[cl][i+1] >= 1 && n_cd[cl][i+2] >= 1){
			n_cd[cl][i]--; n_cd[cl][i+1]--; n_cd[cl][i+2]--;
			n_set++;
			flag = 1;
			i = -1;
		}
	}
	return flag;
}

void rm_sets(int cl){
	rm_id_sets(cl, -1);
	rm_seq_sets(cl);
}