#!python3



import sys

iim = lambda: map(int, sys.stdin.readline().rstrip().split())



X = (10**18).bit_length()



def f(a, s, n):

    if s[-1] == "1":

        return 1



    B = [None] * X

    for i in range(n-1, -1, -1):

        ai, si = a[i], s[i]



        if si == "0":

            while True:

                x = ai.bit_length() - 1

                if B[x] == ai: break

                elif B[x] == None:

                    B[x] = ai

                    break

                ai ^= B[x]

        else:

            while True:

                x = ai.bit_length() - 1

                if B[x] == ai: break

                elif B[x] == None:

                    return 1

                ai ^= B[x]

    return 0





def resolve():

    T = int(input())



    ans = []

    for i in range(T):

        N = int(input())

        A = list(iim())

        S  = input()



        ans.append(f(A, S, N))



    print(*ans, sep="\n")



if __name__ == "__main__":

    resolve()

#!python3



import sys

iim = lambda: map(int, sys.stdin.readline().rstrip().split())



def f(a, s, n):

    if s[-1] == "1":

        return 1



    X = max(a).bit_length()

    B = [None] * X

    for i in range(n-1, -1, -1):

        ai, si = a[i], s[i]



        if si == "0":

            while True:

                x = ai.bit_length() - 1

                if B[x] == ai: break

                elif B[x] == None:

                    B[x] = ai

                    X -= 1

                    if X == 0:

                        return 0

                    break

                ai ^= B[x]

        else:

            while True:

                x = ai.bit_length() - 1

                if B[x] == ai: break

                elif B[x] == None:

                    return 1

                ai ^= B[x]

    return 0





def resolve():

    T = int(input())



    ans = []

    for i in range(T):

        N = int(input())

        A = list(iim())

        S  = input()



        ans.append(f(A, S, N))



    print(*ans, sep="\n")



if __name__ == "__main__":

    resolve()

#!python3
import sys

iim = lambda: map(int, sys.stdin.readline().rstrip().split())
X = (10**18).bit_length()


def f(a, s, n):
    if s[-1] == "1":
        return 1
    B = [None] * X
    for i in range(n - 1, -1, -1):
        ai, si = a[i], s[i]
        if si == "0":
            while True:
                x = ai.bit_length() - 1
                if B[x] == ai:
                    break
                elif B[x] == None:
                    B[x] = ai
                    break
                ai ^= B[x]
        else:
            while True:
                x = ai.bit_length() - 1
                if B[x] == ai:
                    break
                elif B[x] == None:
                    return 1
                ai ^= B[x]
    return 0


def resolve():
    T = int(input())
    ans = []
    for i in range(T):
        N = int(input())
        A = list(iim())
        S = input()
        ans.append(f(A, S, N))
    print(*ans, sep="\n")


if __name__ == "__main__":
    resolve()

#!python3
import sys

iim = lambda: map(int, sys.stdin.readline().rstrip().split())


def f(a, s, n):
    if s[-1] == "1":
        return 1
    X = max(a).bit_length()
    B = [None] * X
    for i in range(n - 1, -1, -1):
        ai, si = a[i], s[i]
        if si == "0":
            while True:
                x = ai.bit_length() - 1
                if B[x] == ai:
                    break
                elif B[x] == None:
                    B[x] = ai
                    X -= 1
                    if X == 0:
                        return 0
                    break
                ai ^= B[x]
        else:
            while True:
                x = ai.bit_length() - 1
                if B[x] == ai:
                    break
                elif B[x] == None:
                    return 1
                ai ^= B[x]
    return 0


def resolve():
    T = int(input())
    ans = []
    for i in range(T):
        N = int(input())
        A = list(iim())
        S = input()
        ans.append(f(A, S, N))
    print(*ans, sep="\n")


if __name__ == "__main__":
    resolve()

-X = (10**18).bit_length() +    X = max(a).bit_length() +                    X -= 1 +                    if X == 0: +                        return 0