/* Rummy (????????????????????????????????´???) */

using rummy_card;
using System;

namespace rummy_card
{
    public enum ColorOfCard
    {
        WHITE,RED,GREEN,BLUE
    }

    class Program
    {
        static void Main(string[] args)
        {
            int n = ReadNumber();

            for(int i = 0; i < n; i++)
            {
                Hand rummyHand = new Hand();

                Console.WriteLine(rummyHand.IsWinner() ? "1" : "0");
                
            }

        }
        

        /// <summary>
        /// ?¨?????????????????????????????????´??°??????????????¨???????????????????????????
        /// AOJ????????§??????????????????
        /// </summary>
        /// <returns>??????????????????????????°????????????????????£?????´??°???</returns>
        private static int ReadNumber()
        {
            int n = 0;
            if(!int.TryParse( Console.ReadLine() , out n))
            {
                /*???????????±??????????????\????????? ?????????????????´???????????????0?????????*/
                Console.WriteLine("error:ReadNumber");
            }
            return n;
        }
    }
}

/// <summary>
/// ??????????????????
/// </summary>
public class Card
{
    /// <summary>
    /// ???????????????
    /// </summary>
    public ColorOfCard _color = ColorOfCard.WHITE;

    /// <summary>
    /// ??????????????°???
    /// </summary>
    public int _number = 0 ;

    /// <summary>
    /// ????????????ID
    /// ??°??????????????????????????????4??????????????§??????????????§1???4???????????????????????¨??????
    /// </summary>
    public int _id = 0;

    
    /// <summary>
    /// ?????????????????????
    /// Hand???????????????????????????????????°??????
    /// ????????´???_id???Hand???????????????
    /// </summary>
    public Card(string color,string number)
    {
        _color = GetColorOfCard(color);
        _number = int.Parse(number);
    }

    private ColorOfCard GetColorOfCard(string color)
    {
        switch (color)
        {
            case "R":
                return ColorOfCard.RED;

            case "G":
                return ColorOfCard.GREEN;

            case "B":
                return ColorOfCard.BLUE;

            default:
                Console.WriteLine("error:GetColor");
                return ColorOfCard.WHITE;
        }
    }
}

/// <summary>
/// ???????????????
/// 9??????????????????????????¨???????????? ?????????????????§??????
/// </summary>
public class Hand
{
    Card[] _cards = new Card[9];

    /// <summary>
    /// ?????????????????????
    /// ?????°?????????AOJ????????¨?????????
    /// </summary>
    public Hand()
    {
        string[] number = Console.ReadLine().Split(' ');
        string[] color = Console.ReadLine().Split(' ');

        for(int i = 0; i < 9; i++)
        {
            _cards[i] = new Card(color[i],number[i]);
            int ID = 1;                                 //???????????????_id

            for(int j = 0; j < i; j++)
            {
                if( _cards[j]._color  == _cards[i]._color &&
                    _cards[j]._number == _cards[i]._number)
                {
                    ID++;       //?????¨??°???????????´???????????????????????????????????????????????????ID?????????????????????????????????
                }
            }
            _cards[i]._id = ID;
        }
        Sort();                 //??????????????±????????????????????£?????????????????????????????????
    }

    /// <summary>
    /// ???????????¶????????¨??????????????????????????°??¨???
    /// </summary>
    internal void Display()
    {
        for(int i = 0; i < 9; i++)
        {
            string str = "W";

            switch (_cards[i]._color)
            {
                case ColorOfCard.RED:
                    str = "R";
                    break;

                case ColorOfCard.GREEN:
                    str = "G";
                    break;

                case ColorOfCard.BLUE:
                    str = "B";
                    break;

                default:
                    /* str = "W" */
                    break;
            }

            Console.Write( str + _cards[i]._number + "({0}) " ,_cards[i]._id);
        }
        Console.WriteLine();
    }

    internal bool IsWinner()
    {
        /*?????£????????????true ?????£?????????????????????false*/
        bool[] flag = new bool[9];

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


            if (!flag[i])   //??°??????????????????????????????????????§??????????????????????????????????????????????????????????????¨???????????????
            {
                MeldGroup(flag, i);
            }

            if (!flag[i])   //???????????£????????§????????????????????????
            {
                MeldRun(flag, i);
            }

            if (!flag[i])
            {

                return false;       //??????????????±??????????????????????????????????????£??????????????§?????????                            
            }
        }
        /*false???????????????for???????????????????????´?????¨??????flag???true*/

        return true;
    }

    /// <summary>
    /// ????????°?????¶????????¨??? ???????????°??¨
    /// </summary>
    /// <param name="flag"></param>
    private void ShowFlag(bool[] flag)
    {
        foreach(bool x in flag)
        {
            Console.Write( x ? "1 " : "0 ");
        }
        Console.WriteLine();
    }

    /// <summary>
    /// ????????§???????????§??????????????????
    /// </summary>
    /// <param name="flag">???????????????????????£???????????£???????????????</param>
    /// <param name="i">???????????°</param>
    private void MeldRun(bool[] flag, int i)
    {
        for (int j = i+1; j < 9; j++)    //???????????£?????????????????????????????§??°??????1??§????????????????????????????????????
        {
            if(_cards[i]._color == _cards[j]._color && 
               _cards[i]._number + 1 == _cards[j]._number &&
                    !flag[j] )
            {
                for (int k = j + 1; k < 9; k++)     //1??§?????????????????????????????£?????????????§????2??§????????????????????????????????????
                {
                    if (_cards[i]._color == _cards[k]._color &&
                       _cards[i]._number + 2 == _cards[k]._number &&
                            !flag[k])
                    {
                        flag[i] = true;
                        flag[j] = true;
                        flag[k] = true;
                        return;
                    }
                }
            }
        }
    }

    /// <summary>
    /// ??°???????????§???????????§??????????????????
    /// </summary>
    /// <param name="flag">???????????????????????£???????????£???????????????</param>
    /// <param name="i">???????????°</param>
    private void MeldGroup(bool[] flag, int i)
    {
        if(_cards[i]._color == _cards[i+2]._color && _cards[i]._number == _cards[i+2]._number)
        {
            flag[i]   = true;
            flag[i+1] = true;
            flag[i+2] = true;
        }
    }

    /// <summary>
    /// ???????????´????????????????????????
    /// </summary>
    internal void Sort()
    {
        Array.Sort( _cards, (a, b) => Compare(a, b) );
    }

    /// <summary>
    /// 2?????????????????? ??? > ??°??? > ID ?????????????????§????????????
    /// </summary>
    /// <param name="a">??????????±?</param>
    /// <param name="b">??????????±?</param>
    /// <returns></returns>
    private int Compare(Card a, Card b)
    {
        int iCompare = a._color.CompareTo(b._color);    //??????????????§????????????
        if (iCompare != 0)
        {
            return iCompare ;              
        }
        else                        //?????????????????°??????????????§????????????
        {
            if( a._number - b._number != 0)
            {
                return a._number - b._number;
            }
            else                    //??°??????????????????id???????????§????????????
            {
                return a._id - b._id;
            }
        }
        
    }
}

Measured memory_bytes: 9160