#include <stdio.h>

int main(void) {
	int d_num,d_cur;
	int card_num[3][10];
	int nums[9];
	char colors[9][4];
	int i;
	int ok;
	scanf("%d",&d_num);
	for(d_cur=0;d_cur<d_num;d_cur++) {
		for(i=0;i<9;i++)scanf("%d",&nums[i]);
		for(i=0;i<9;i++)scanf("%s",colors[i]);
		for(i=0;i<10;i++) {
			card_num[0][i]=card_num[1][i]=card_num[2][i]=0;
		}
		for(i=0;i<9;i++) {
			card_num[colors[i][0]=='R'?0:colors[i][0]=='G'?1:2][nums[i]]++;
		}
		for(i=2;i<10;i++) {
			while(card_num[0][i-2] && card_num[0][i-1] && card_num[0][i]) {
				card_num[0][i-2]--;card_num[0][i-1]--;card_num[0][i]--;
			}
			while(card_num[1][i-2] && card_num[1][i-1] && card_num[1][i]) {
				card_num[1][i-2]--;card_num[1][i-1]--;card_num[1][i]--;
			}
			while(card_num[2][i-2] && card_num[2][i-1] && card_num[2][i]) {
				card_num[2][i-2]--;card_num[2][i-1]--;card_num[2][i]--;
			}
		}
		for(i=0;i<10;i++) {
			card_num[0][i]%=3;
			card_num[1][i]%=3;
			card_num[2][i]%=3;
		}
		ok=1;
		for(i=0;i<10;i++) {
			if(card_num[0][i])ok=0;
			if(card_num[1][i])ok=0;
			if(card_num[2][i])ok=0;
		}
		printf("%d\n",ok);
	}
	return 0;
}