#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
int T; pair<int, int>x[9], y[9];
vector<int>vec;
int main() {
	cin >> T;
	for (int i = 0; i < T; i++) {
		for (int j = 0; j < 9; j++) { cin >> y[j].second; }
		for (int j = 0; j < 9; j++) {
			char c; cin >> c;
			if (c == 'R') { y[j].first = 0; }
			if (c == 'G') { y[j].first = 1; }
			if (c == 'B') { y[j].first = 2; }
		}
		bool OK2 = false;
		int a[9] = { 0,1,2,3,4,5,6,7,8 };
		do {
			for (int j = 0; j < 9; j++) {
				x[a[j]] = y[j];
			}
			bool OK = true;
			for (int j = 0; j < 3; j++) {
				if (x[j * 3].first != x[j * 3 + 1].first) { OK = false; }
				if (x[j * 3 + 1].first != x[j * 3 + 2].first) { OK = false; }
				if (x[j * 3].second != x[j * 3 + 1].second) { goto E; }
				if (x[j * 3 + 1].second != x[j * 3 + 2].second) { OK = false; }
				goto F; E:;
				if (x[j * 3].second + 1 != x[j * 3 + 1].second) { OK = false; }
				if (x[j * 3 + 1].second + 1 != x[j * 3 + 2].second) { OK = false; }
			F:;
			}
			if (OK == true) { OK2 = true; }
		} while (next_permutation(a, a + 9));
		if (OK2 == true) { vec.push_back(1); }
		else { vec.push_back(0); }
	}
	for (int i = 0; i < vec.size(); i++) { cout << vec[i] << endl; }
	return 0;
}