#include <iostream>
#include <vector>

using namespace std;

void solve()
{
	int T;
	cin >> T;
	for(int i = 0; i < T; ++i)
	{
		vector< vector<int> > data(3, vector<int>(10));
		vector<int> num(9);
		for(int i = 0; i < 9; ++i)
		{
			cin >> num[i];
		}
		vector<char> color(9);
		for(int i = 0; i < 9; ++i)
		{
			cin >> color[i];
		}
		for(int i = 0; i < 9; ++i)
		{
			if(color[i] == 'R')
			{
				data[0][num[i]]++;
			}
			else if(color[i] == 'G')
			{
				data[1][num[i]]++;
			}
			else if(color[i] == 'B')
			{
				data[2][num[i]]++;
			}
		}
		int count = 0;
		for(int i = 0; i < 3; ++i)
		{
			for(int j = 1; j <= 9; ++j)
			{
				if(data[i][j] >= 3)
				{
					++count;
					data[i][j] -= 3;
				}
			}
		}
		for(int i = 0; i < 3; ++i)
		{
			for(int j = 1; j <= 7; ++j)
			{
				while(data[i][j] >= 1 && data[i][j + 1] >= 1 && data[i][j + 2] >= 1)
				{
					++count;
					data[i][j] -= 1;
					data[i][j + 1] -= 1;
					data[i][j + 2] -= 1;
				}
			}
		}
		if(count == 3)
		{
			cout << 1 << endl;
		}
		else
		{
			cout << 0 << endl;
		}
	}
}

int main()
{
	solve();
	return(0);
}