T = int(eval(input()))

for _ in range(T):

    N = int(eval(input()))

    A = [int(i) for i in input().split()]

    S = eval(input())



    B = []

    ans = 0

    for a, s in zip(reversed(A), reversed(S)):

        for b in B:

            a = min(a, a ^ b)



        if a:

            if s == "1":

                ans = 1

                break

            else:

                B.append(a)



    print(ans)
T = int(eval(input()))

for _ in range(T):

    N = int(eval(input()))

    A = [int(i) for i in input().split()]

    S = eval(input())



    B = []

    ans = 0

    for a, s in zip(reversed(A), reversed(S)):

        for b in B:

            a = min(a, a ^ b)



        if a:

            if s == "1":

                ans = 1

                break

            B.append(a)



    print(ans)
T = int(eval(input()))
for _ in range(T):
    N = int(eval(input()))
    A = [int(i) for i in input().split()]
    S = eval(input())
    B = []
    ans = 0
    for a, s in zip(reversed(A), reversed(S)):
        for b in B:
            a = min(a, a ^ b)
        if a:
            if s == "1":
                ans = 1
                break
            else:
                B.append(a)
    print(ans)

T = int(eval(input()))
for _ in range(T):
    N = int(eval(input()))
    A = [int(i) for i in input().split()]
    S = eval(input())
    B = []
    ans = 0
    for a, s in zip(reversed(A), reversed(S)):
        for b in B:
            a = min(a, a ^ b)
        if a:
            if s == "1":
                ans = 1
                break
            B.append(a)
    print(ans)

-            else: -                B.append(a) +            B.append(a)