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

int main(){
  int n;
  std::cin >> n;
  for (int l = 0; l < n; l++) {
    vector<vector<int> > cards(3, vector<int>(11, 0));
    vector<int> number(10), color(10);
    for (int i = 0; i < 9; i++) std::cin >> number[i];
    for (int i = 0; i < 9; i++) {
      char c;
      std::cin >> c;
      if(c == 'R'){
        cards[0][number[i]]++;
      }else if(c == 'B'){
        cards[1][number[i]]++;
      }else if(c == 'G'){
        cards[2][number[i]]++;
      }
    }
    for (int i = 0; i < 3; i++) {
      for (int j = 0; j < 9; j++) {
        if(cards[i][j] < 0){
          std::cout << 0 << std::endl;
          i = j = 1e9;
          break;
        }
        cards[i][j] %= 3;
        cards[i][j + 1] -= cards[i][j], cards[i][j + 2] -= cards[i][j];
      }
      if(i == 2)std::cout << 1 << std::endl;
    }
    
  }

  return 0;
}

