#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

bool IsSet(vector<int> x, size_t size)
{
  if (size == 3) {
    if (x[0] == x[1] and x[1] == x[2]) {
      return true;
    }
    if (x[0] + 1 == x[1] and x[1] + 1 == x[2]) {
      return true;
    }
  }
  else if (size == 6) {
    vector<int> y(3), z(3);
    bool flag = false;
    for (int i = 0; i < 3; i++) {
      y[i] = x[i];
      z[i] = x[i + 3];
    }
    flag = IsSet(y, 3) and IsSet(z, 3);
    if (flag) {
      return true;
    }
    int r1, r2;
    for (int i = 1; i < 6; i++) {
      if (x[i] == x[0] + 1) {
        flag = true;
        r1 = i;
      }
    }
    if (not flag) {
      return false;
    }
    flag = false;
    for (int i = 2; i < 6; i++) {
      if (x[i] == x[0] + 2) {
        flag = true;
        r2 = i;
      }
    }
    if (not flag) {
      return false;
    }
    vector<int> copy(6);
    for (int i = 0; i < 6; i++) {
      copy[i] = x[i];
    }
    copy.erase(copy.begin() + r2);
    copy.erase(copy.begin() + r1);
    copy.erase(copy.begin());
    flag = IsSet(copy, 3);
    return flag;
  }
  else if (size == 9) {
    vector<int> y(3), z(3), w(3);
    bool flag = false;
    for (int i = 0; i < 3; i++) {
      y[i] = x[i];
      z[i] = x[i + 3];
      w[i] = x[i + 6];
    }
    flag = IsSet(y, 3) and IsSet(z, 3) and IsSet(w, 3);
    if (flag) {
      return true;
    }
    int r1, r2;
    for (int i = 1; i < 9; i++) {
      if (x[i] == x[0] + 1) {
        flag = true;
        r1 = i;
      }
    }
    if (not flag) {
      return false;
    }
    flag = false;
    for (int i = 2; i < 9; i++) {
      if (x[i] == x[0] + 2) {
        flag = true;
        r2 = i;
      }
    }
    if (not flag) {
      return false;
    }
    vector<int> copy(9);
    for (int i = 0; i < 9; i++) {
      copy[i] = x[i];
    }
    copy.erase(copy.begin() + r2);
    copy.erase(copy.begin() + r1);
    copy.erase(copy.begin());
    flag = IsSet(copy, 6);
    return flag;

  }
  return false;
  
}

bool IsSets(vector<int> color)
{
  if (color.size() == 0) {
    return true;
  }
  sort(color.begin(), color.end());
  return IsSet(color, color.size());
}

int main()
{
  int t;
  cin >> t;
  for (int j = 0; j < t; j++) {
    int num[9];
    for (int i = 0; i < 9; i++) {
      cin >> num[i];
    }
    char color[9];
    for (int i = 0; i < 9; i++) {
      cin >> color[i];
    }
    vector<int> red, green, blue;
    for (int i = 0; i < 9; i++) {
      if (color[i] == 'R') {
        red.push_back(num[i]);
      }
      else if (color[i] == 'G') {
        green.push_back(num[i]);
      }
      else if (color[i] == 'B') {
        blue.push_back(num[i]);
      }
    }
    if (red.size() % 3 != 0 or green.size() % 3 != 0 or blue.size() %3 != 0) {
      cout << '0' << endl;
      continue;
    }

    bool flag = true;
    flag = IsSets(red);
    if (flag == false) {
      cout << '0' << endl;
      continue;
    }
    flag = IsSets(green);
    if (flag == false) {
      cout << '0' << endl;
      continue;
    }
    flag = IsSets(blue);
    if (flag == false) {
      cout << '0' << endl;
      continue;
    }

    cout << '1' << endl;
  }
  return 0;
}

Measured memory_bytes: 1208