t = int(eval(input()))

for _ in range(t):

	n = int(eval(input()))

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

	s = eval(input())

	basis = []

	ans = 0

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

		if s[i] == "0":

			for b in basis:

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

			if a[i]:

				basis.append(a[i])

		else:

			for b in basis:

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

			if a[i]:

				ans = 1

				break

	print(ans)
for _ in range(int(eval(input()))):

	n = int(eval(input()))

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

	s = eval(input())

	basis = []

	ans = 0

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

		for b in basis:

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

		if a[i]:

			if s[i] == "0":

				basis.append(a[i])

			else:

				ans = 1

				break

	print(ans)
t = int(eval(input()))
for _ in range(t):
    n = int(eval(input()))
    a = list(map(int, input().split()))
    s = eval(input())
    basis = []
    ans = 0
    for i in range(n - 1, -1, -1):
        if s[i] == "0":
            for b in basis:
                a[i] = min(a[i], a[i] ^ b)
            if a[i]:
                basis.append(a[i])
        else:
            for b in basis:
                a[i] = min(a[i], a[i] ^ b)
            if a[i]:
                ans = 1
                break
    print(ans)

for _ in range(int(eval(input()))):
    n = int(eval(input()))
    a = list(map(int, input().split()))
    s = eval(input())
    basis = []
    ans = 0
    for i in range(n - 1, -1, -1):
        for b in basis:
            a[i] = min(a[i], a[i] ^ b)
        if a[i]:
            if s[i] == "0":
                basis.append(a[i])
            else:
                ans = 1
                break
    print(ans)

-t = int(eval(input())) -for _ in range(t): +for _ in range(int(eval(input()))): -        if s[i] == "0": -            for b in basis: -                a[i] = min(a[i], a[i] ^ b) -            if a[i]: +        for b in basis: +            a[i] = min(a[i], a[i] ^ b) +        if a[i]: +            if s[i] == "0": -        else: -            for b in basis: -                a[i] = min(a[i], a[i] ^ b) -            if a[i]: +            else: