using System;

namespace ConsoleApplication6
{
    class Program
    {
        static void Main(string[] args)
        {
            string inputT = Console.ReadLine();
            int T = int.Parse(inputT);
            int[,] cn = new int[3, 9];

            for (int i = 0; i < T; i++)
            {
                int win = 0;
                string[] inputnumber = Console.ReadLine().Split(' ');
                string[] inputcolor = Console.ReadLine().Split(' ');

                for (int j = 0; j < 9; j++) //RGB*(1???9)?????????????????´?????????1??\????¶????
                {
                    string color = inputcolor[j];
                    int number = int.Parse(inputnumber[j]);
                    for (int L = 1; L < 10; L++)
                    {
                        if (color == "R" && number == L)
                        {
                            cn[0, number - 1] += 1;
                        }
                        else if (color == "G" && number == L)
                        {
                            cn[1, number - 1] += 1;
                        }
                        else if (color == "B" && number == L)
                        {
                            cn[2, number - 1] += 1;
                        }
                    }
                }

                for (int k = 0; k < 3; k++) //win?????¶
                {
                    for (int h = 0; h < 9; h++)
                    {
                        if (cn[k, h] >= 3) //????????°????????¨???
                        {
                            if (cn[k, h] < 6)
                            {
                                win += 1; //?????????????????????
                                cn[k, h] = cn[k, h] - 3; //???????????????
                            }
                            else if (cn[k, h] < 9)
                            {
                                win += 2; //?????????????????????
                                cn[k, h] = cn[k, h] - 6; //???????????????
                            }
                            else if (cn[k, h] == 9)
                            {
                                win += 2; //?????????????????????
                                cn[k, h] = cn[k, h] - 9; //???????????????
                            }
                            //Console.WriteLine("a");
                        }
                        if (h > 1)
                        { 
                            if ((cn[k, h] >= 1) && (cn[k, h - 1] >= 1) && (cn[k, h - 2] >= 1)) //??£????????¨???
                            {
                                if ((cn[k, h] < 2) || (cn[k, h - 1] < 2) || (cn[k, h - 2] < 2))
                                {
                                    win += 1; // ?????????????????????
                                    cn[k, h] = cn[k, h] - 1; // ????????????
                                    cn[k, h - 1] = cn[k, h - 1] - 1;
                                    cn[k, h - 2] = cn[k, h - 2] - 1;
                                }
                                else if ((cn[k, h] < 3) || (cn[k, h - 1] < 3) || (cn[k, h - 2] < 3))
                                {
                                    win += 2; // ?????????????????????
                                    cn[k, h] = cn[k, h] - 2; // ????????????
                                    cn[k, h - 1] = cn[k, h - 1] - 2;
                                    cn[k, h - 2] = cn[k, h - 2] - 2;
                                }
                                else if ((cn[k, h] == 3) && (cn[k, h - 1] == 3) && (cn[k, h - 2] == 3))
                                {
                                    win += 1; // ?????????????????????
                                    cn[k, h] = cn[k, h] - 1; // ????????????
                                    cn[k, h - 1] = cn[k, h - 1] - 1;
                                    cn[k, h - 2] = cn[k, h - 2] - 1;
                                }

                                //Console.WriteLine("b");
                             }
                        }
                    }
                }

                if (win >= 3) //????????¨???
                    Console.WriteLine(1);
                else if (win < 3)
                    Console.WriteLine(0);
                for (int x = 0; x < 3; x++) // cn?????????
                {
                    for (int y = 0; y < 9; y++)
                    {
                        cn[x, y] = 0;
                    }
                }
            }

        }
    }
}

Measured memory_bytes: 9268