T = int(eval(input()))



for _ in range(T):

    N = int(eval(input()))

    A = list(map(int,input().split()))

    S = eval(input())



    if S[-1] == '1':

        print((1))

        continue



    list0 = [0] * 64



    for a, s in zip(A[::-1], S[::-1]):

        blen = a.bit_length()

        for i in range(blen, 0, -1):

            if a.bit_length() < i: continue

            if list0[i - 1]:

                a ^= list0[i - 1]

                if a == 0: break



        else:

            if s == '1':

                ans = 1

                break

            else:

                list0[a.bit_length() - 1] = a



    else:

        ans = 0



    print(ans)

T = int(eval(input()))



for _ in range(T):

    N = int(eval(input()))

    A = list(map(int,input().split()))

    S = eval(input())



    list0 = [0] * 64



    for a, s in zip(A[::-1], S[::-1]):

        if s == '1':

            while a:

                b = a.bit_length() - 1

                if list0[b]:

                    a ^= list0[b]

                else:

                    break



            if a:

                ans = 1

                break



        else:

            while a:

                b = a.bit_length() - 1

                if list0[b]:

                    a ^= list0[b]

                else:

                    list0[b] = a

                    break



    else:

        ans = 0



    print(ans)

T = int(eval(input()))
for _ in range(T):
    N = int(eval(input()))
    A = list(map(int, input().split()))
    S = eval(input())
    if S[-1] == "1":
        print((1))
        continue
    list0 = [0] * 64
    for a, s in zip(A[::-1], S[::-1]):
        blen = a.bit_length()
        for i in range(blen, 0, -1):
            if a.bit_length() < i:
                continue
            if list0[i - 1]:
                a ^= list0[i - 1]
                if a == 0:
                    break
        else:
            if s == "1":
                ans = 1
                break
            else:
                list0[a.bit_length() - 1] = a
    else:
        ans = 0
    print(ans)

T = int(eval(input()))
for _ in range(T):
    N = int(eval(input()))
    A = list(map(int, input().split()))
    S = eval(input())
    list0 = [0] * 64
    for a, s in zip(A[::-1], S[::-1]):
        if s == "1":
            while a:
                b = a.bit_length() - 1
                if list0[b]:
                    a ^= list0[b]
                else:
                    break
            if a:
                ans = 1
                break
        else:
            while a:
                b = a.bit_length() - 1
                if list0[b]:
                    a ^= list0[b]
                else:
                    list0[b] = a
                    break
    else:
        ans = 0
    print(ans)

-    if S[-1] == "1": -        print((1)) -        continue -        blen = a.bit_length() -        for i in range(blen, 0, -1): -            if a.bit_length() < i: -                continue -            if list0[i - 1]: -                a ^= list0[i - 1] -                if a == 0: +        if s == "1": +            while a: +                b = a.bit_length() - 1 +                if list0[b]: +                    a ^= list0[b] +                else: -        else: -            if s == "1": +            if a: -            else: -                list0[a.bit_length() - 1] = a +        else: +            while a: +                b = a.bit_length() - 1 +                if list0[b]: +                    a ^= list0[b] +                else: +                    list0[b] = a +                    break