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

namespace ProblemA
{
    class Program
    {
        static void Main(string[] args)
        {
            var T = int.Parse(Console.ReadLine());
            var res = new int[T];
            for (int loop = 0; loop < T; loop++)
            {
                var N = int.Parse(Console.ReadLine());
                var As = Console.ReadLine().Split(' ').Select(x => long.Parse(x)).ToArray();
                var S = Console.ReadLine().ToCharArray();

                if (S.Last() == '1')
                    res[loop] = 1;
                else if (S.All(x => x == '0'))
                    res[loop] = 0;
                else
                {
                    res[loop] = SolveMainCase(As, S);
                }
                    
            }
            for (int loop = 0; loop < T; loop++)
            {
                Console.WriteLine(res[loop]);
            }
        }

        static int SolveMainCase(long[] As, char[] S)
        {
            var winZeroList = new List<long>() { 0 , As[S.Length - 1]};
            for (int i = S.Length - 2; i >= 0; i--)
            {
                if(S[i] == '0')
                {
                    AddBasisSet(As[i], winZeroList);
                }
                else
                {
                    var lenZero = winZeroList.Count();
                    AddBasisSet(As[i], winZeroList);
                    if (winZeroList.Count() > lenZero)
                        return 1;
                }
            }
            return 0;
        }

        static int SolveMainCase_My(long[] As, char[] S)
        {
            var winOne = false;
            int indForZeroStart, indForOneStart;
            try
            {
                indForZeroStart = S.Select((x, i) => new { x, i }).Where(s => s.x == '1').Last().i + 1;
            }
            catch
            {
                indForZeroStart = 0;
            }
            try
            {
                indForOneStart = S.Select((x, i) => new { x, i }).Where(e => e.x == '0' && e.i < indForZeroStart).Last().i + 1;
            }
            catch
            {
                indForOneStart = 0;
            }
            var listZero = new List<long>() { 0, As[indForZeroStart] };
            var listOne = new List<long>() { 0, As[indForOneStart] };
            for (int i = indForZeroStart + 1; i < S.Length; i++)
            {
                AddBasisSet(As[i], listZero);
            }
            for (int i = indForOneStart + 1; i < indForZeroStart; i++)
            {
                AddBasisSet(As[i], listOne);
            }
            var lenZero = listZero.Count();
            foreach (var oneElement in listOne)
            {
                AddBasisSet(oneElement, listZero);
                if (listZero.Count() > lenZero)
                    winOne = true;
            }
            return winOne ? 1 : 0;
        }

        static void AddBasisSet(long a, List<long> orgList)
        {
            for (int i = 0; i < orgList.Count(); i++)
            {
                a = Math.Min(a, a ^ orgList[i]);
            }
            if (a > 0)
                orgList.Add(a);
        }
    }
}


Measured memory_bytes: 31804