#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cstring>

using namespace std;

int card[3][10];

bool solve(){

	int cnt = 0;

	for(int c=0; c<3; ++c){
		for(int k=1; k<=9; ++k){
			
			//counting same-card set
			cnt += card[c][k]/3;
			card[c][k] %= 3;
				
			if(k<=7){
				
				//counting serial-number set
				int sub = min(card[c][k], min(card[c][k+1], card[c][k+2]));

				for(int i=0; i<3; ++i){
					card[c][k+i] -= sub;
				}

				cnt += sub;
			}
		}
	}
	
	return cnt>=3;
}

int main(){
	
	int n;
	cin>>n;

	while(n--){
			
		int a[10];
			
		memset(card, 0, sizeof(card));

		for(int i=0; i<9; ++i){
			cin>>a[i];
		}

		for(int i=0; i<9; ++i){

			char b;
			cin>>b;
			card[b=='R'?0:b=='G'?1:2][a[i]]++;
		}

		cout << solve() << endl;
	}	
	
	return 0;
}