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))
class VectorSpace01:

    def __init__(self):

        self.E = []

    

    def chk(self, n):

        for e in self.E:

            n = min(n, n ^ e)

        return 1 if n == 0 else 0

    

    def add(self, n):

        for e in self.E:

            n = min(n, n ^ e)

        if n: self.E.append(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 = VectorSpace01()

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

        a = vs.add(A[i])

        if S[i] and a == 0:

            print((1))

            break

    else:

        print((0))
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))

class VectorSpace01:
    def __init__(self):
        self.E = []

    def chk(self, n):
        for e in self.E:
            n = min(n, n ^ e)
        return 1 if n == 0 else 0

    def add(self, n):
        for e in self.E:
            n = min(n, n ^ e)
        if n:
            self.E.append(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 = VectorSpace01()
    for i in range(N)[::-1]:
        a = vs.add(A[i])
        if S[i] and a == 0:
            print((1))
            break
    else:
        print((0))

-class VectorSpace: -    def __init__(self, k): -        self.k = k -        self.E = [0] * k +class VectorSpace01: +    def __init__(self): +        self.E = [] -        for i in range(self.k)[::-1]: -            n = min(n, n ^ self.E[i]) +        for e in self.E: +            n = min(n, n ^ e) -        for i in range(self.k)[::-1]: -            n = min(n, n ^ self.E[i]) +        for e in self.E: +            n = min(n, n ^ e) -            self.E[n.bit_length() - 1] = n +            self.E.append(n) -    vs = VectorSpace(60) +    vs = VectorSpace01()