#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <queue>
#include <sstream>

using namespace std;

int pat[16][3] = {{1, 1, 1}, {2, 2, 2}, {3, 3, 3}, {4, 4, 4}, {5, 5, 5}, {6, 6, 6}, {7, 7, 7}, {8, 8, 8}, {9, 9, 9}, {1, 2, 3}, {2, 3, 4}, {3, 4, 5}, {4, 5, 6}, {5, 6, 7}, {6, 7, 8}, {7, 8, 9}};

int main(){
	
	int T;
	cin >> T;
	
	for(int loop = 0; loop < T; loop++){
		
		int count[9][3];
		int sum[9][3];
		int number[9];
		int color[9];
		
		for(int i = 0; i < 9; i++){
			cin >> number[i];
		}
		
		for(int i = 0; i < 9; i++){
			string str;
			cin >> str;
			if(str[0] == 'R'){
				color[i] = 0;
			}else if(str[0] == 'G'){
				color[i] = 1;
			}else{
				color[i] = 2;
			}
		}
		
		for(int i = 0; i < 9; i++){
			for(int j = 0; j < 3; j++){
				count[i][j] = 0;
			}
		}
		
		for(int i = 0; i < 9; i++){
			count[number[i]][color[i]]++;
		}
		
		bool flag = false;
		
		for(int i = 0; i < 48; i++){
			for(int j = 0; j < 48; j++){
				for(int k = 0; k < 48; k++){
					int index11 = i % 16;
					int index12 = i / 16;
					int index21 = j % 16;
					int index22 = j / 16;
					int index31 = k % 16;
					int index32 = k / 16;
					for(int l = 0; l < 9; l++){
						for(int m = 0; m < 3; m++){
							sum[l][m] = 0;
						}
					}
					for(int l = 0; l < 3; l++){
						sum[pat[index11][l]][index12]++;
						sum[pat[index21][l]][index22]++;
						sum[pat[index31][l]][index32]++;
					}
					bool flag2 = true;
					for(int l = 0; l < 9; l++){
						for(int m = 0; m < 3; m++){
							if(sum[l][m] != count[l][m]){
								flag2 = false;
							}
						}
					}
					if(flag2){
						flag = true;
					}
				}
			}
		}
		
		cout << flag << endl;
		
	}
	
	return 0;
}