using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace rummy
{
    class Program
    {
        static void Main(string[] args)
        {
            //??????????????°????¨????
            var read_text = Console.ReadLine();
            int round_num = int.Parse(read_text);

            //??????????????°???????????????
            for(var i = 0;i<round_num;i++)
            {
                var read_num = Console.ReadLine();
                var read_color = Console.ReadLine();

                var HandCard_obj = new HandCard(read_num, read_color);

                Console.WriteLine(HandCard_obj.judge_math() ? "1":"0");

            }

        }
    }

    /// <summary>
    /// ???????????????
    /// </summary>
    class HandCard
    {

        /// <summary>
        /// ???????????°?????¨????????????
        /// </summary>
        int[] hand_card_num = new int[9];
        string[] hand_card_color = new string[9];

        /// <summary>
        /// ????????????????¨????
        /// </summary>
        //public enum Color
        //{
        //    red,
        //    blue,
        //    gleen

        //}

        /// <summary>
        /// ?????????????????????
        /// ??????????????????
        /// </summary>
        /// <param name="card_num">?????????????????????????????????????????????</param>
        /// <param name="card_color">???????????????????????????????????????</param>
        public HandCard(string card_num,string card_color)
        {
            var sprit_num=card_num.Split(' ');
            var sprit_color=card_color.Split(' ');

            for(int i=0;i<sprit_num.Length;i++)
                hand_card_num[i] = int.Parse(sprit_num[i]);

            for (int i = 0; i < sprit_color.Length; i++)
                hand_card_color[i] = sprit_color[i] ;
        }

        /// <summary>
        /// ????????????????????¶?????????????????????????????§????????????
        /// </summary>
        /// <returns></returns>
        public bool judge_math()
        {
            int win_flg = 0;
            //????????????
            var color = new string[]{"R", "G", "B"};
            
            //??????????????¨?????????
            string judge_string="";

            foreach (string s in color)
            {
                if (color_filtering(s).Count > 0)
                {
                    if (color_filtering(s).Count % 3 != 0)
                        return false;

                    var judge_list = color_filtering(s);

                    foreach (int c in judge_list)
                        judge_string += c.ToString();

                    for (var i = 1; i <= 9; i++)
                    {

                        //???????????????
                        if (0 <= judge_string.IndexOf(i.ToString() + i.ToString() + i.ToString()))
                        {
                            win_flg++;
                            for (var j = 0; j < 3; j++)
                                judge_list.Remove(i);

                            if (judge_list.Count() < 3)
                                break;

                            judge_string = "";
                            foreach (int c in judge_list)
                                judge_string += c.ToString();

                            i--;

                        }
                    }

                    for (var i = 1; i < 8; i++)
                    {
                        if (judge_list.Contains(i) && judge_list.Contains(i + 1) && judge_list.Contains(i + 2))
                        {
                            win_flg++;
                            for (var j = 0; j < 3; j++)
                                judge_list.Remove(i + j);

                            if (judge_list.Count() < 3)
                                break;
                            i--;
                        }
                    }

                }
            }
            return win_flg >= 3 ? true:false;
        }

        /// <summary>
        /// ????????????????????????????????°??????????????§??????
        /// </summary>
        /// <param name="color">??????????????? R,G,B?????????</param>
        /// <returns>?????????????????????List</returns>
        private List<int> color_filtering(string  color)
        {
            //?????????????????????????????????????????????
            List<int> math_num = new List<int>();

            //???????????????????????????????????§?????´???????????????????????????????????????????????????????????\??????
            for(var i=0;i<hand_card_color.Length;i++)
                if(hand_card_color[i]==color)
                    math_num.Add(hand_card_num[i]);

            //???????????????????????????
            math_num.Sort();
            return math_num;
        }

    }
}

Measured memory_bytes: 10508