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 i = 0; i < 3; i++) {
				switch (i) {
				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);

				// ????????????(true)?????¨???flgCount???+1??????
				if (!ck.numberCheck()) {
					flgCount++;
				}
				ck.numClear();
				//System.out.println(flgCount);
			}
			// ?????? flgCount?????????1??\????????¨???1?????????
			sb.append(flgCount == 0 ? "1\n" : "0\n");

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

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

	}
}

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

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??¨??????

	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 count1 = 0; count1 < COLUMN_NUMBER; count1++) {
			if (scanColor[count1].equals(color)) {
				numberStore(scanNumber[count1]);
			}
		}
	}

	/**
	 * 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 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();

	}

	/**
	 * num[9]???????????¨????????????0??§????????¨???true????????????1?????§???1??\???????????°false?????????
	 * @return
	 */
	// ?????????true ??? false??§??????
	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: 29588