def solve():

  n=int(eval(input()))

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

  s=eval(input())

  base=[]

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

    v=a[i]

    for x in base:

      v=min(v,v^x)

    if v:

      if s[i]=='0':

        base.append(v)

      else:

        return 1

  return 0



t=int(eval(input()))

for _ in range(t):

  print((solve()))
def solve():

  n=int(eval(input()))

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

  s=eval(input())

  base=[]

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

    v=a[i]

    for x in base:

      v=min(v,v^x)

    if v:

      if s[i]=='0':

        base.append(v)

      else:

        return 1

  return 0



def main():

  t=int(eval(input()))

  for _ in range(t):

    print((solve()))



if __name__ == '__main__':

  main()
def solve():
    n = int(eval(input()))
    a = list(map(int, input().split()))
    s = eval(input())
    base = []
    for i in range(n - 1, -1, -1):
        v = a[i]
        for x in base:
            v = min(v, v ^ x)
        if v:
            if s[i] == "0":
                base.append(v)
            else:
                return 1
    return 0


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

def solve():
    n = int(eval(input()))
    a = list(map(int, input().split()))
    s = eval(input())
    base = []
    for i in range(n - 1, -1, -1):
        v = a[i]
        for x in base:
            v = min(v, v ^ x)
        if v:
            if s[i] == "0":
                base.append(v)
            else:
                return 1
    return 0


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


if __name__ == "__main__":
    main()

-t = int(eval(input())) -for _ in range(t): -    print((solve())) +def main(): +    t = int(eval(input())) +    for _ in range(t): +        print((solve())) + + +if __name__ == "__main__": +    main()