// Aizu 2102: Rummy
// 2017.9.20 bal4u@uu

#include <stdio.h>
#include <string.h>

int f[3][15];
char tr['Z'];
int v[10];

int main()
{
	int t, i, j, n;
	char c[5];

	tr['R'] = 0, tr['G'] = 1, tr['B'] = 2;
	scanf("%d", &t); while (t-- > 0) {
		memset(f, 0, sizeof(f));
		for (i = 0; i < 9; i++) scanf("%d", v+i);
		for (i = 0; i < 9; i++) scanf("%s", c), f[tr[*c]][v[i]]++;
		for (n = 0, j = 0; j < 3; j++)	for (i = 1; i <= 9; i++) {
			while (f[j][i] > 0 && f[j][i+1] > 0 && f[j][i+2] > 0)
				n++, f[j][i]--, f[j][i+1]--, f[j][i+2]--;
			if (n == 3) goto Done;
		}
		for (j = 0; j < 3; j++) for (i = 1; i <= 9; i++) {
			while (f[j][i] >= 3) n++, f[j][i] -= 3;
			if (n == 3) goto Done;
		}
Done:	puts(n == 3 ? "1" : "0");
	}
	return 0;
}