#include<stdio.h>
#define ll long long
#define ii pair<int,int>
ll ara[300];
char st[300];
int main()
{
    ll a,b,c,d,m,n,i,j,k,l,t,x,y,z;
    ll ans=0;
    ll maxi=0,mini=0,sum=0,mul=1;

    scanf("%lld",&t);

    while(t--)
    {
        scanf("%lld",&n);
        for(i=0;i<n;i++)
        {
            scanf("%lld",&ara[i]);
        }
        scanf("%s",&st);

        l=strlen(st);
        x=0;


        for(i=0;i<l;i++)
        {

            if(st[i]=='0')
            {
                if(x^ara[i]==0)
                    x=x^ara[i];



                else
                    continue;
            }
            if(st[i]=='1')
            {
                if((x^ara[i])!=0)
                    x=x^ara[i];

                else
                    continue;

            }

        }
        if(x==0)
            printf("%lld\n",x);
        else
        {
            x=1;
            printf("%lld\n",x);
        }

    }

    return 0;
}




