#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
 
using namespace std;

/* constant */

/* typedef */

/* global variables */

int nis[9];
int ccds[3][9], csums[3];

/* subroutines */

bool rec(int k, int *cds) {
  if (k == 0) return true;

  for (int i = 0; i < 9; i++)
    if (cds[i] >= 3) {
      cds[i] -= 3;
      bool ok = rec(k - 3, cds);
      cds[i] += 3;
      if (ok) return true;
    }

  for (int i = 0; i < 7; i++)
    if (cds[i] && cds[i + 1] && cds[i + 2]) {
      cds[i]--, cds[i + 1]--, cds[i + 2]--;
      bool ok = rec(k - 3, cds);
      cds[i]++, cds[i + 1]++, cds[i + 2]++;
      if (ok) return true;
    }

  return false;
}

/* main */

int main() {
  int tn;
  cin >> tn;
  while (tn--) {
    memset(ccds, 0, sizeof(ccds));
    memset(csums, 0, sizeof(csums));

    for (int i = 0; i < 9; i++) cin >> nis[i];
    for (int i = 0; i < 9; i++) {
      char c;
      cin >> c;
      int ci = (c == 'R') ? 0 : (c == 'G') ? 1 : 2;

      ccds[ci][nis[i] - 1]++;
      csums[ci]++;
    }

    if (false)
      for (int i = 0; i < 3; i++) {
	for (int j = 0; j < 9; j++) cout << ccds[i][j] << ' ';
	cout << "= " << csums[i] << endl;
      }

    bool ok = true;
    for (int i = 0; ok && i < 3; i++)
      ok = (csums[i] % 3 == 0) && rec(csums[i], ccds[i]);

    cout << ok << endl;
  }

  return 0;
}