#include <iostream>
#include <utility>
#include <algorithm>
#include <cassert>

using namespace std;

bool
is_seq_set(int a, int b, int c) {
  if (a+2==c && b+1==c)
    return true;
  return false;
}

bool
is_same_set(int a, int b, int c) {
  if (a==c && b==c)
    return true;
  return false;
}

bool
is_good_set(int a, int b, int c) {
  return is_seq_set(a,b,c) || is_same_set(a,b,c);
}

bool
has_satisfy_set(int card[]) {
  return
    is_good_set(card[0], card[1], card[2]) &&
    is_good_set(card[3], card[4], card[5]) &&
    is_good_set(card[6], card[7], card[8]);
}

bool
check_all(int card[9]) {
  int s = 0;
  sort(card, card+9);
  do {
    bool has_satisfy = has_satisfy_set(card);
    if (has_satisfy) {
      /*
      cout << "found satisfied card " << endl;
      for (int i=0; i<9; ++i) {
	auto c = card[i];
	cout << c << " ";
      }
      cout << endl;
      */
      return true;
    }

    // s++;
  } while (next_permutation(card, card+9));
  // cout << "s = " << s << endl;
  return false;
}

int
main() {
  int n;
  cin >> n;
  for (int i=0;i<n; ++i) {
    int card[9];
    for (int j=0; j<9; ++j) {
      cin >> card[j];
      // cout << card[j] << " ";
    }
    // cout << endl;
    string color;
    int shift[] {0, 10, 20};
    for (int j=0; j<9; ++j) {
      cin >> color;
      // cout << color << " ";
      int idx = 0;
      switch(color[0]) {
      case 'R': idx = 0; break;
      case 'G': idx = 1; break;
      case 'B': idx = 2; break;
      default: assert(0);
      }
      card[j] += shift[idx];

      // cout << card[j] << " ";
    }
    // cout << endl;
    
    cout << check_all(card) << endl;
    // cout << "Not found ...." << endl;
  }
  
  return 0;
}