import java.io.IOException;
import java.util.Scanner;

public class Main{

	public static void main(String[] args) throws IOException {

		Scanner sc = new Scanner(System.in);

		int gameset = sc.nextInt();

		CardRummy cr = new CardRummy();

		for(int j2 =0; j2 < gameset; j2++){

			for (int i = 0; i < CardRummy.CARDPAGE; i++) {
				for (int j = 0; j < CardRummy.ONECARDSET; j++) {
					if (i == 0)
						cr.card[i][j] = sc.nextInt();
					else {
						switch (sc.next()) {
						case "R":
							cr.card[i][j] = CardRummy.RED;
							break;
						case "G":
							cr.card[i][j] = CardRummy.GREEN;
							break;
						case "B":
							cr.card[i][j] = CardRummy.BLUE;
							break;
						}
					}
				}
			}
			cr.setCardset(cr.card);
			cr.card = cr.getCardset();

			// game start
			int cnt = 0;
			cnt = cr.playtheGame(cr.card); // ?????????
			// game result
			if (3 <= cnt)
				System.out.println(1);
			else
				System.out.println(0);
		}
	}
}

class CardRummy {

	// declear
	static final int ONECARDSET = 9;
	static final int CARDPAGE = 2;

	// num
	final int NUMBER0 = 0;
	final int NUMBER1 = 1;
	final int NUMBER2 = 2;
	final int NUMBER3 = 3;
	final int NUMBER4 = 4;
	final int NUMBER5 = 5;
	final int NUMBER6 = 6;
	final int NUMBER7 = 7;
	final int NUMBER8 = 8;
	final int NUMBER9 = 9;

	// color
	static final int RED = 1;
	static final int GREEN = 2;
	static final int BLUE = 3;

	int[][] card = new int[CARDPAGE][ONECARDSET];
	CardRummy[][] ArrCR = new CardRummy[CARDPAGE][ONECARDSET];

	public CardRummy() {

	}

	public int[][] getCardset() {
		return card;
	}

	// ????????????????????????????????\??????
	public void setCardset(int[][] card) {
		this.card = settingcardplay(card);
	}

	public int[][] settingcardplay(int[][] card) {// Error point

		// ?????¬??¨????????¬??????????????????????±???????????????????for????????????
		for (int i = 0; i < 8; i++) {
			for (int j = 0; j < 8 - i; j++) {
				// [0][i] : num, [1][j] : color

				// ?????????color???????????????
				if (card[1][j] > card[1][j + 1]) {
					// ???????????????????????????????????¨????????°?????£?¨????????????????????????????
					int temp = card[1][j];
					card[1][j] = card[1][j + 1];
					card[1][j + 1] = temp;

					int temp2 = card[0][j];
					card[0][j] = card[0][j + 1];
					card[0][j + 1] = temp2;
				}
			}
		}
		// ?????¬??¨????????¬??????????????????????±???????????????????for????????????
		for (int i = 0; i < 8; i++) {
			for (int j = 0; j < 8 - i; j++) {
				// ??????color&num???????????????
				if (card[1][j] == card[1][j + 1] && card[0][j] > card[0][j + 1]) {
					// ?????????????????????
					int temp = card[0][j];
					card[0][j] = card[0][j + 1];
					card[0][j + 1] = temp;
				}
			}
		}
		return card;
	}

	public int playtheGame(int[][] cardset) { // ?????????
		// [0][i] : num, [1][j] : color

		int cnt = 0;
		// ??????for????????????????¬??????¨???????????????
		// ex : [0][1][2] ....
		for (int i = 0; i < 7; i++) {
			for (int j = i + 1; j < 8; j++) {
				for (int k = j + 1; k < 9; k++) {

					// 3??????????????????????????°
					if (cardset[1][i] == cardset[1][j] && cardset[1][j] == cardset[1][k]) {
						// ??£????????????????¢????
						if (cardset[0][i] != 0 && cardset[0][i] == cardset[0][j] && cardset[0][i] == cardset[0][k]) {
							// ??????????????¶????????????????????????
							cnt++;
							// ?????????????????????????????????????????????
							cardset[0][i] = 0;
							cardset[0][j] = 0;
							cardset[0][k] = 0;
						}
					}
				}
			}
		}

		for (int i = 0; i < 7; i++) {

			for (int j = i + 1; j < 8; j++) {

				for (int k = j + 1; k < 9; k++) {
					// 3??????????????????????????°
					if (cardset[1][i] == cardset[1][j] && cardset[1][j] == cardset[1][k]) {
						// ?????????????????????????¢????
						if (cardset[0][i] != 0 && cardset[0][i] == cardset[0][j] - 1
								&& cardset[0][i] == cardset[0][k] - 2) {
							// Error point
							// ??????????????¶????????????????????????
							cnt++;
							// ?????????????????????????????????????????????
							cardset[0][i] = 0;
							cardset[0][j] = 0;
							cardset[0][k] = 0;
						}
					}
				}
			}
		}
		// ???????????°????????????main????????????????????????????????????
		return cnt;
	}
}

Measured memory_bytes: 28932