#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define _GLIBCXX_DEBUG

void print(vector<int> l) {
  for (int i : l) {
    cout << i;
  }
  cout << endl;
}

int main() {
  int T;
  cin >> T;
  for (int n = 0; n < T; n++) {
    bool ans = true;
    vector<int> a, b, c;
    vector<int> cardN(9);
    for (int i = 0; i < 9; i++)
      cin >> cardN[i];
    for (int i = 0; i < 9; i++) {
      string cardC;
      cin >> cardC;
      if (cardC == "R")
        a.push_back(cardN[i]);
      if (cardC == "G")
        b.push_back(cardN[i]);
      if (cardC == "B")
        c.push_back(cardN[i]);
    }

    if ((a.size() % 3) || (b.size() % 3) || (c.size() % 3)) {
			cout<<0<<endl;//最初はans=falseにしてた
      continue;
    }

    for (vector<int> nv : {a, b, c}) {
      sort(nv.begin(), nv.end());
      while (nv.size() != 0) {
        if ((nv[0] == nv[1]) && (nv[1] == nv[2]))
          nv.erase(nv.begin(), nv.begin() + 3);
				//eraseの２つめの引数は削除したい範囲の次を指す
        else {
          auto p2 = find(nv.begin(), nv.end(), nv[0] + 1);
          auto p3 = find(nv.begin(), nv.end(), nv[0] + 2);
          if ((p2 != end(nv)) && (p3 != end(nv))) {
            nv.erase(p3);
            nv.erase(p2);
						nv.erase(nv.begin());//最初忘れてた
						/*nv.erase(nv.begin());
            nv.erase(p2);
            nv.erase(p3);//ミス
						*/
          } else {
            ans = false;
            break;
          }
        }
      }
    }

    cout << ans << endl;
  }
}

