#include <iostream>
#include <algorithm>
#include <utility>
#include <string>

using namespace std;
int T;
int card[9];
char color;
bool judge;

int is_win();
bool is_all_good_set();
bool is_good_set(int, int, int);
bool is_same_number(int,int, int);
bool is_sequence(int, int, int);

int main(){

  cin >> T;
  for (int j = 0; j < T; ++j){

    for (int i = 0; i < 9; ++i){
      cin >> card[i];      
    }

    for (int i = 0; i < 9; ++i){
      cin >> color;
      if(color == 'B') card[i] += 10;
      else if (color == 'G') card[i] += 20;
    }
    
    cout << is_win() << endl;

/*
    //test
    cout << is_sequence(1,2,3) << endl; 
    cout << is_sequence(3,4,5) << endl;
    cout << is_same_number(27,27,27) << endl;
for (int i = 0; i < 9; ++i)
  {
   cout << card[i]<< " ";
  }
  cout << endl;
  cout << "*********" << endl;    
  is_all_good_set();

*/

  }

return 0;

}

int is_win(){

  sort(card, card + 9);

  do{
/*
  for (int i = 0; i < 9; ++i)
  {
   cout << card[i];
  }
  cout << endl;
*/
    if(is_all_good_set()){
    return 1;
  }
  } while (next_permutation(card, card + 9));

  return 0;
}

bool is_all_good_set(){

  int judge = 0;
  for (int i = 0; i < 3; ++i)
  {
    judge += is_good_set(card[3*i], card[3*i+ 1], card[3*i + 2]);
  }

  if (judge == 3){
    
    return true;
  }

/*
  if(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]) ){
    return true;
  }
*/
  else return false;
}

/*
1
1 2 3 3 4 5 7 7 7
R R R R R R G G G
*/

bool is_good_set(int a, int b, int c){

   if(is_same_number(a,b,c) ||  is_sequence(a,b,c) ) return true;
   else return false;

}

bool is_same_number(int a, int b, int c){

  if(a == b && b == c) return true;
  else return false;

} 

bool is_sequence(int a, int b, int c){

  if( a + 2 == b + 1 && b +1 == c ) return true;
  else return false ;

}