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 n = scan.nextInt();

		// R,G,B???????????\??????????????°
		String colorStr = "";

		// R,G,B???????????§false?????¨???+1???????????????
		int flgCount = 0;

		// CheckResult???????????????????????????????????????
		CheckResult ck = new CheckResult();

		// n??????????????????
		for (int count = 0; count < n; count++) {

			// CheckResult?????????????????????????????????????´?
			for (int i = 0; i < COLUMN_NUMBER; i++) {
				ck.scanNumber[i] = scan.nextInt();
			}
			for (int i = 0; i < COLUMN_NUMBER; i++) {
				ck.scanColor[i] = scan.next();
			}

			// R,G,B????????????????????????????????????????????????
			for (int colorNumber = 0; colorNumber < 3; colorNumber++) {
				switch (colorNumber) {
				case 0:// R(??¬??????)?????´??? colorStr???R?????????
					colorStr = "R";
					break;
				case 1:// G(??°?????????)?????´??? colorStr???G?????????
					colorStr = "G";
					break;
				case 2:// B(?????????)?????´??? colorStr???B?????????
					colorStr = "B";
					break;
				}

				// colorStr(???)?????????????????°??????CheckResult????????????numberStor?????????????????????
				ck.getColorToNumber(colorStr);

				// ????????????(false)?????¨???flgCount???+1??????
				if (!ck.numberCheck()) {
					flgCount++;
				}
				
				// CheckResult???????????§?????¨??????(??????)num[]????????????
				ck.numClear();

			}
			
			
			
			// ?????? flgCount?????????0?????¨???1?????????
			sb.append(flgCount == 0 ? "1\n" : "0\n");

			// flgCount????????????
			flgCount = 0;

		}
		// ????????????????????????
		sb.deleteCharAt(sb.length() - 1);
		// ???????????????
		System.out.println(new String(sb));

	}
}

// --------------------checkResult?????????------------------------------------
class CheckResult {

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

	// Scanner????????\??????????????????????´?????????????
	public int scanNumber[] = new int[COLUMN_NUMBER];
	public String scanColor[] = new String[COLUMN_NUMBER];

	// ????????°?????????????????¨???????????? ???????????????????????§????´?
	// ????????????num[]??????????????????0????????£??????true??¨??????

	// num[1]???[9]?????§?????°???????????°????¢?????????????????????????
	private int[] num = new int[COLUMN_NUMBER];

	/**
	 * color??????????????????
	 * scanColor??¨???????????§????????°????????????scanNumber?????????CheckResult????????????numberStore???????????????
	 * 
	 * @param color
	 */
	public void getColorToNumber(String color) {
		// color??§??????????????????????????§????????°scanColor???????????????scanNumber?????????CheckResult????????????numberStore???????????????
		for (int i = 0; i < COLUMN_NUMBER; i++) {
			if (scanColor[i].equals(color)) {
				numberStore(scanNumber[i]);
			}
		}
	}

	/**
	 * getColorNumber???????????????????????????(??????)num[]???????´????
	 * ??? (??????)num[]?????°????????°???????´?????????????
	 * @param number
	 */
	private void numberStore(int number) {
		num[number - 1] = num[number - 1] + 1;
	}

	/**
	 * ??\??????????????°?????§????????????3?????\???????????´?????¨?????£???????????£???????????´?????? ?????????????????? ??????????????´??????true????????????????????´??????false?????????
	 */
	public boolean numberCheck() {
		// ????????°??????????????\???????????´???????????????
		// ?????§??§3?????????????????????
		for (int i=0;i<COLUMN_NUMBER;i++){
			if(num[i] >=3 ){
				num[i] -= 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();

	}

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

	/**
	 * ??????num??????????????????
	 */
	public void numClear() {
		num = new int[COLUMN_NUMBER];
	}

}

Measured memory_bytes: 29284