#include <iostream>
#include <string>
#include <vector>
using namespace std;

bool isZero(vector<vector<int> > &v) {
    for (int i=0; i<v.size(); ++i) {
        for (int j=0; j<v[i].size(); ++j) {
            if (v[i][j] != 0) {
                return false;
            }
        }
    }
    return true;
}

int judge(vector<vector<int> > &v, int cnt) {
    if (cnt == 3 && isZero(v)) {
        return 1;
    }
    for (int i=0; i<3; ++i) {
        for (int j=0; j<9; ++j) {
            if (3 <= v[i][j]) {
                v[i][j] -= 3;
                if (judge(v, cnt + 1) == 1) {
                    return 1;
                } else {
                    v[i][j] += 3;
                }
            }
            if (j+2 < 9 && v[i][j] && v[i][j+1] && v[i][j+2]) {
                v[i][j] --; v[i][j+1] --; v[i][j+2] --;
                if (judge(v, cnt + 1) == 1) {
                    return 1;
                } else {
                    v[i][j] ++; v[i][j+1] ++; v[i][j+2] ++;
                }
            }
        }
    }
    return 0;
}

int main() {
    int t; cin >> t;
    while (t--) {
        vector<int> num(9);
        for (int i=0; i<9; ++i) cin >> num[i];
        vector<char> color(9);
        for (int i=0; i<9; ++i) cin >> color[i];

        vector<vector<int> > v(3, vector<int>(9));
        for (int i=0; i<9; ++i) {
            if (color[i] == 'R') {
                v[0][num[i]-1] ++;
            } else if (color[i] == 'G') {
                v[1][num[i]-1] ++;
            } else if (color[i] == 'B') {
                v[2][num[i]-1] ++;
            }
        }

        cout << judge(v, 0) << endl;
    }
    return 0;
}