from heapq import heappush, heappop





def calcSpace():

    H = []

    hpush = lambda x: heappush(H, -x)

    hpop = lambda: -heappop(H)

    for x in X:

        hpush(x)

    

    E = [0] * 60

    while H:

        x = hpop()

        b = x.bit_length() - 1

        if E[b]:

            x ^= E[b]

            if x: hpush(x)

        else:

            E[b] = x

    

    return E

    

def chk(y):

    y0 = y

    for i in range(60)[::-1]:

        if y >> i & 1:

            if V[i]:

                y ^= V[i]

                # print("chk", y0, "OK", V)

                if y == 0: return 1

            else:

                return 0



def chk_all():

    for y in Y:

        if chk(y) == 0:

            return 1

            break

    else:

        return 0

    

T = int(eval(input()))

for _ in range(T):

    N = int(eval(input()))

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

    S = [int(a) for a in eval(input())]

    

    if 0:

        print(("N =", N))

        print(("A =", A))

        print(("S =", S))

    

    X = []

    Y = []

    i = N - 1

    ans = 0

    while i >= 0:

        while i >= 0:

            if S[i]: break

            X.append(A[i])

            i -= 1

        while i >= 0:

            if S[i] == 0: break

            Y.append(A[i])

            i -= 1



            V = calcSpace()

            # print("X =", X)

            # print("Y =", Y)

            # print("V =", V)

            if chk_all():

                ans = 1

                i = -1

    print(ans)
class VectorSpace:

    def __init__(self, k):

        self.k = k

        self.E = [0] * k

    

    def chk(self, n):

        for i in range(self.k)[::-1]:

            n = min(n, n ^ self.E[i])

        return 1 if n == 0 else 0

    

    def add(self, n):

        for i in range(self.k)[::-1]:

            n = min(n, n ^ self.E[i])

        if n: self.E[n.bit_length() - 1] = n

        return 1 if n == 0 else 0

    

    def dimension(self):

        return len(self.E)



T = int(eval(input()))

for _ in range(T):

    N = int(eval(input()))

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

    S = [int(a) for a in eval(input())]

    vs = VectorSpace(60)

    for i in range(N)[::-1]:

        a = vs.add(A[i])

        if S[i] and a == 0:

            print((1))

            break

    else:

        print((0))
from heapq import heappush, heappop


def calcSpace():
    H = []
    hpush = lambda x: heappush(H, -x)
    hpop = lambda: -heappop(H)
    for x in X:
        hpush(x)
    E = [0] * 60
    while H:
        x = hpop()
        b = x.bit_length() - 1
        if E[b]:
            x ^= E[b]
            if x:
                hpush(x)
        else:
            E[b] = x
    return E


def chk(y):
    y0 = y
    for i in range(60)[::-1]:
        if y >> i & 1:
            if V[i]:
                y ^= V[i]
                # print("chk", y0, "OK", V)
                if y == 0:
                    return 1
            else:
                return 0


def chk_all():
    for y in Y:
        if chk(y) == 0:
            return 1
            break
    else:
        return 0


T = int(eval(input()))
for _ in range(T):
    N = int(eval(input()))
    A = [int(a) for a in input().split()]
    S = [int(a) for a in eval(input())]
    if 0:
        print(("N =", N))
        print(("A =", A))
        print(("S =", S))
    X = []
    Y = []
    i = N - 1
    ans = 0
    while i >= 0:
        while i >= 0:
            if S[i]:
                break
            X.append(A[i])
            i -= 1
        while i >= 0:
            if S[i] == 0:
                break
            Y.append(A[i])
            i -= 1
            V = calcSpace()
            # print("X =", X)
            # print("Y =", Y)
            # print("V =", V)
            if chk_all():
                ans = 1
                i = -1
    print(ans)

class VectorSpace:
    def __init__(self, k):
        self.k = k
        self.E = [0] * k

    def chk(self, n):
        for i in range(self.k)[::-1]:
            n = min(n, n ^ self.E[i])
        return 1 if n == 0 else 0

    def add(self, n):
        for i in range(self.k)[::-1]:
            n = min(n, n ^ self.E[i])
        if n:
            self.E[n.bit_length() - 1] = n
        return 1 if n == 0 else 0

    def dimension(self):
        return len(self.E)


T = int(eval(input()))
for _ in range(T):
    N = int(eval(input()))
    A = [int(a) for a in input().split()]
    S = [int(a) for a in eval(input())]
    vs = VectorSpace(60)
    for i in range(N)[::-1]:
        a = vs.add(A[i])
        if S[i] and a == 0:
            print((1))
            break
    else:
        print((0))

-from heapq import heappush, heappop +class VectorSpace: +    def __init__(self, k): +        self.k = k +        self.E = [0] * k +    def chk(self, n): +        for i in range(self.k)[::-1]: +            n = min(n, n ^ self.E[i]) +        return 1 if n == 0 else 0 -def calcSpace(): -    H = [] -    hpush = lambda x: heappush(H, -x) -    hpop = lambda: -heappop(H) -    for x in X: -        hpush(x) -    E = [0] * 60 -    while H: -        x = hpop() -        b = x.bit_length() - 1 -        if E[b]: -            x ^= E[b] -            if x: -                hpush(x) -        else: -            E[b] = x -    return E +    def add(self, n): +        for i in range(self.k)[::-1]: +            n = min(n, n ^ self.E[i]) +        if n: +            self.E[n.bit_length() - 1] = n +        return 1 if n == 0 else 0 - -def chk(y): -    y0 = y -    for i in range(60)[::-1]: -        if y >> i & 1: -            if V[i]: -                y ^= V[i] -                # print("chk", y0, "OK", V) -                if y == 0: -                    return 1 -            else: -                return 0 - - -def chk_all(): -    for y in Y: -        if chk(y) == 0: -            return 1 -            break -    else: -        return 0 +    def dimension(self): +        return len(self.E) -    if 0: -        print(("N =", N)) -        print(("A =", A)) -        print(("S =", S)) -    X = [] -    Y = [] -    i = N - 1 -    ans = 0 -    while i >= 0: -        while i >= 0: -            if S[i]: -                break -            X.append(A[i]) -            i -= 1 -        while i >= 0: -            if S[i] == 0: -                break -            Y.append(A[i]) -            i -= 1 -            V = calcSpace() -            # print("X =", X) -            # print("Y =", Y) -            # print("V =", V) -            if chk_all(): -                ans = 1 -                i = -1 -    print(ans) +    vs = VectorSpace(60) +    for i in range(N)[::-1]: +        a = vs.add(A[i]) +        if S[i] and a == 0: +            print((1)) +            break +    else: +        print((0))