#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>

#define N 9


int cmpfunc (const void * a, const void * b)
{
   return ( *(int*)a - *(int*)b );
}


bool is_set(int a, int b, int c) {
  if (a == b && b == c) return true;
  int array[] = {a, b, c};
  qsort(array, 3, sizeof(int), cmpfunc);
  if (array[2] - array[1] == 1 && array[1] - array[0] == 1) return true;
  return false;
}

void array_remove3(int old_array[], int new_array[], int old_length, int a, int b, int c) {
  int i, new_index = 0;
  bool a_set = false, b_set = false, c_set = false;
  int old_array_copy[old_length];

  for (i = 0; i < old_length; i++) {
    old_array_copy[i] = old_array[i];
  }


  
  for (i = 0; i < old_length; i++) {
    if (!a_set && old_array_copy[i] == a) {
      old_array_copy[i] = -1;
      a_set = true;
    }
    if (!b_set && old_array_copy[i] == b) {
      old_array_copy[i] = -1;
      b_set = true;
    }
    if (!c_set && old_array_copy[i] == c) {
      old_array_copy[i] = -1;
      c_set = true;
    }
  }
  for (i = 0; i < old_length; i++) {
    if (old_array_copy[i] != -1) {
      new_array[new_index] = old_array_copy[i];
      new_index++;
    }
  }
 


}


  
  

bool solve_backtrack(int array[], int array_length, bool reset) {
  int i, j, k, l;
  static bool solved = false;
  if (reset) solved = false;
  
  if (array_length == 0) {
    solved = true;
    return true;
  }
  
  for (i = 0; i < array_length; i++) {
    for (j = i+1; j < array_length; j++) {
      for (k = j+1; k < array_length; k++) {
	
	if (is_set(array[i], array[j], array[k])) {
	  //printf("set: i is %d, j is %d, k is %d\n", array[i], array[j], array[k]);
	  int new_length = array_length - 3;
	  if (new_length == 0) {
	    //printf("new length is 0\n");
	    solved = true;
	    return true;
	  }
	  int new_array[new_length];
	  array_remove3(array, new_array, array_length, array[i], array[j], array[k]);
	  
	   
	  // printf("new index is %d\n", new_index);
	  solve_backtrack(new_array, new_length, false);
	  
	}
      }
    }
  }
  return solved;
}
	      




int main(int argc, char *argv[])
{

  int entries;
  int i, j;

  fscanf(stdin, "%d", &entries);
 

  
  for (i = 0; i < entries; i++) {
    int array[N], red[N], blue[N], green[N];
    int red_n = 0, blue_n = 0, green_n = 0;
    for (j = 0; j < N; j++) {
      fscanf(stdin, "%d", &array[j]);
    }
    char color;
    for (j = 0; j < N; j++) {
      fscanf(stdin, " %c", &color);
      if (color == 'R') {
	red[red_n] = array[j];
	red_n++;
      } else if (color == 'B') {
	blue[blue_n] = array[j];
	blue_n++;
      } else if (color == 'G') {
	green[green_n] = array[j];
	green_n++;
      }
    }
    
    if (red_n % 3 != 0 || blue_n % 3 != 0 || green_n % 3 != 0) {
      printf("0\n");
    } else if (solve_backtrack(red, red_n, true) && solve_backtrack(blue, blue_n, true) && solve_backtrack(green, green_n, true)) {
      printf("1\n");
    } else {
      printf("0\n");
    }
  }
  
  
 

  return 0;
}