# 解説AC

def solve():

    n=int(eval(input()))

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

    s=eval(input())

    basis=[]

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

      	# 基底を求める

        for e in basis:

            a[i]=min(a[i],a[i]^e)

        if a[i]:

            if s[i]=="0":

                basis.append(a[i])

            else:

                print((1))

                return

    print((0))



t=int(eval(input()))

for _ in range(t):

    solve()
# F_2 ^nの基底クラス

class F2n:

    # LISTを受け取ってbasisを生成する.(掃き出し法)

    def __init__(self,LIST):

        self.basis = []

        for ele in LIST:

            for vec in self.basis:

                ele = min(ele, vec^ele)

            if ele:

                self.basis.append(ele)

    # basisに要素eleを追加できるなら追加しTrueを返す. 追加できないなら何もせず,Falseを返す.

    def Add(self, ele):

        for vec in self.basis:

            ele = min(ele, ele^vec)

        if ele:

            self.basis.append(ele)

            return True

        else:

            return False



def solve():

    n=int(eval(input()))

    a=list(map(int,input().split()))[::-1]

    s=input()[::-1]

    h=F2n([])

    for i in range(n):

        if h.Add(a[i]):

            if s[i]=="1":

                print((1))

                return

    print((0))

t=int(eval(input()))

for _ in range(t):

    solve()
# 解説AC
def solve():
    n = int(eval(input()))
    a = list(map(int, input().split()))
    s = eval(input())
    basis = []
    for i in range(n - 1, -1, -1):
        # 基底を求める
        for e in basis:
            a[i] = min(a[i], a[i] ^ e)
        if a[i]:
            if s[i] == "0":
                basis.append(a[i])
            else:
                print((1))
                return
    print((0))


t = int(eval(input()))
for _ in range(t):
    solve()

# F_2 ^nの基底クラス
class F2n:
    # LISTを受け取ってbasisを生成する.(掃き出し法)
    def __init__(self, LIST):
        self.basis = []
        for ele in LIST:
            for vec in self.basis:
                ele = min(ele, vec ^ ele)
            if ele:
                self.basis.append(ele)

    # basisに要素eleを追加できるなら追加しTrueを返す. 追加できないなら何もせず,Falseを返す.
    def Add(self, ele):
        for vec in self.basis:
            ele = min(ele, ele ^ vec)
        if ele:
            self.basis.append(ele)
            return True
        else:
            return False


def solve():
    n = int(eval(input()))
    a = list(map(int, input().split()))[::-1]
    s = input()[::-1]
    h = F2n([])
    for i in range(n):
        if h.Add(a[i]):
            if s[i] == "1":
                print((1))
                return
    print((0))


t = int(eval(input()))
for _ in range(t):
    solve()

-# 解説AC +# F_2 ^nの基底クラス +class F2n: +    # LISTを受け取ってbasisを生成する.(掃き出し法) +    def __init__(self, LIST): +        self.basis = [] +        for ele in LIST: +            for vec in self.basis: +                ele = min(ele, vec ^ ele) +            if ele: +                self.basis.append(ele) + +    # basisに要素eleを追加できるなら追加しTrueを返す. 追加できないなら何もせず,Falseを返す. +    def Add(self, ele): +        for vec in self.basis: +            ele = min(ele, ele ^ vec) +        if ele: +            self.basis.append(ele) +            return True +        else: +            return False + + -    a = list(map(int, input().split())) -    s = eval(input()) -    basis = [] -    for i in range(n - 1, -1, -1): -        # 基底を求める -        for e in basis: -            a[i] = min(a[i], a[i] ^ e) -        if a[i]: -            if s[i] == "0": -                basis.append(a[i]) -            else: +    a = list(map(int, input().split()))[::-1] +    s = input()[::-1] +    h = F2n([]) +    for i in range(n): +        if h.Add(a[i]): +            if s[i] == "1":