#include<iostream>
#include<algorithm>
using namespace std;
int t, card[9];

bool is_same_number(int a, int b, int c) {
    if (a == b && b == c) {
        return true;
    }
    return false;
}
bool is_sequence(int a, int b, int c) {
    if (a + 2 == b + 1 && b + 1 == c) {
        return true;
    }
    return false;
}
bool is_good_set(int a, int b, int c) {
    return is_same_number(a, b, c) || is_sequence(a, b, c);
}
bool is_all_good_set() {
    return is_good_set(card[0], card[1], card[2]) && is_good_set(card[3], card[4], card[5])
    && is_good_set(card[6], card[7], card[8]);
}
int win() {
    sort(card, card + 9);
    do {
        if (is_all_good_set()) {
            return 1;
        }
    } while (next_permutation(card, card + 9));
    return 0;
}
int main() {
    cin >> t;
    for (int tt = 0; tt < t; ++tt) {
        for (int i = 0; i < 9; ++i) {
            cin >> card[i];
        }
        char color;
        for (int i = 0; i < 9; ++i) {
            cin >> color;
            if (color == 'G') {
                card[i] += 10;
            } else if (color == 'B') {
                card[i] += 20;
            }
        }
        cout << win() << endl;
    }
    return 0;
}

