import java.util.*;

public class Main {

	// ?????????9???????????§??????????????°???????????£?????¨??????????????§????????????????????°??¨????????????
	//???CheckResult????????????????§?
	final static int COLUMN_NUMBER = 9;

	@SuppressWarnings("resource")
	public static void main(String args[]) {
		StringBuilder sb = new StringBuilder();
		Scanner scan = new Scanner(System.in);

		int number[] = new int[COLUMN_NUMBER];
		String color[] = new String[COLUMN_NUMBER];

		// ???????????????????´?????????????
		int n = scan.nextInt();

		// n??????????????????
		for (int count = 0; count < n; count++) {
			// ?????????????????????????´???????
			// 9???????????????????´?
			for (int count1 = 0; count1 < COLUMN_NUMBER; count1++) {
				number[count1] = scan.nextInt();
			}
			// 9????????????????´?
			for (int count1 = 0; count1 < COLUMN_NUMBER; count1++) {
				color[count1] = scan.next();
			}

			// ???????????????????????????????????????????????°?????°?????£??????true??§?¬?????????????
			//ColorCountResult c = new ColorCountResult();

			// ?????????????????? store???????????????????????¨??????color_count??????????????????
			//for (int count1 = 0; count1 < COLUMN_NUMBER; count1++) {
			//	c.colorCount(color[count1]);
			//}

			// ???????????? ??????????????°??§????????°true???
			//boolean flg = c.isColorResult();

			// ???????????????true?????´????????°???????????? / false?????´??????0?????????
			//if (flg) {
				CheckResult ck = new CheckResult();
				
				//R(??¬??????????????????
				//9???color?????????????¢???????R??§????????¨??????CheckResult????????????numberStore???????????????
				for(int count1=0;count1<COLUMN_NUMBER;count1++){
					if(color[count1].equals("R")){
						ck.numberStore(number[count1]);
					}
				}
				// ???????????????
				ck.numberSort();

				//???????????????
				boolean flg1 = ck.numberCheck();
				
				//G(??°?????????????????????
				//9???color?????????????¢???????G??§????????¨??????CheckResult????????????numberStore???????????????
				for(int count1=0;count1<COLUMN_NUMBER;count1++){
					if(color[count1].equals("G")){
						ck.numberStore(number[count1]);
					}
				}
				// ???????????????
				ck.numberSort();

				//???????????????
				boolean flg2 = ck.numberCheck();
				
				//B(?????????????????????
				//9???color?????????????¢???????B??§????????¨??????CheckResult????????????numberStore???????????????
				for(int count1=0;count1<COLUMN_NUMBER;count1++){
					if(color[count1].equals("B")){
						ck.numberStore(number[count1]);
					}
				}
				// ???????????????
				ck.numberSort();

				//???????????????
				boolean flg3 = ck.numberCheck();

				// ?????? R(flg1)??¨G(flg2)??¨B(flg3)?????¨???true?????¨???1?????????
				sb.append(flg1 & flg2 & flg3 ? "1\n" : "0\n");

			//} else {
			//	sb.append("0");
			//	sb.append("\n");
			//}
		}
		// ????????????????????????
		sb.deleteCharAt(sb.length() - 1);
		System.out.println(new String(sb));

	}
}

// --------------------color_cout?????????------------------------------------

// ????????°?????°???????????????
class ColorCountResult {

	private int r = 0;
	private int b = 0;
	private int g = 0;
	
	//r b g??????????????????????????????????????????
	public void colorCount(String color) {
		if (color.equals("R")) {
			r++;
		} else if (color.equals("B")) {
			b++;
		} else if (color.equals("G")) {
			g++;
		}
	}

	// color?????\??????
	public boolean isColorResult() {
		// ????????????????????????????????°??§????????¨???true?????????
		return (r % 3 == 0) & (b % 3 == 0) & (g % 3 == 0);
	}

}

// --------------------check?????????------------------------------------

class CheckResult {

	// ?????????9???????????§??????????????°???????????£?????¨??????????????§????????????????????°??¨????????????
	final static int COLUMN_NUMBER = 9;

	private List<Integer> numberList = new ArrayList<Integer>();

	private int[] number = new int[COLUMN_NUMBER];
	
	//????????¨??????????????°???????????????
	private int x = 0;
	
	// ????????°?????????????????¨???????????? ???????????????????????§????´?
	// ????????????num[]??????????????????0????????£??????true??¨??????

	private int[] num = new int[COLUMN_NUMBER];
	// int num[] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 };

	// ??°????????\??????
	public void numberStore(int number) {
		numberList.add(number);
		num[number - 1] = num[number - 1] + 1;
		x++;
	}

	// ??°??????????????????????????????????´?
	public void numberSort() {
		Collections.sort(numberList);
		for (int count = 0; count < x; count++) {
			number[count] = numberList.get(count);
		}
		//?????????????????????
		numberList.clear();
		//????????¨??????????????°????????????
		x = 0;
	}
	/**
	 * ??\??????????????°?????§????????????3?????\???????????´?????¨?????£???????????£???????????´????????????????????????
	 * ??????????????´??????true????????????????????´??????false?????????
	 */
	public boolean numberCheck() {
		// ????????°??????????????\???????????´???????????????
		// ?????§??§3?????????????????????
		for (int count = 0; count < COLUMN_NUMBER; count++) {
			// num[count]??????????????\????????¨??????????????????
			if (num[count] >= 3) {
				num[count] = num[count] - 3;
			}
		}

		// ??£???????????£?????????????¢?????????? ?????§????????????????????????
		// 7????????????????????? (1-2-3)(2-3-4)?????????????¢????????????????
		// ????????§????????£????????????????????????????????????????????????
		for (int count2 = 0; count2 < 3; count2++) {
			for (int count = 0; count < 7; count++) {
				// ???????????°????????£???????¢???????true?????´??????????????????-1??????
				if ((num[count] >= 1) & (num[count + 1] >= 1) & (num[count + 2] >= 1)) {
					num[count]--;
					num[count + 1]--;
					num[count + 2]--;
					break;
				}
			}
		}
		return isNumberResult();

	}

	// ?????????true ??? false??§??????
	private boolean isNumberResult() {
		// num[]????????????????????¨????????§????????°true?????????
		boolean ret = true;
		for(int n : num){
			if (n != 0){
				ret = false;
			}
		}
		return ret;

	}

}

Measured memory_bytes: 28824