### BUGGY CODE ###

import os

import sys
import numpy as np

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")

sys.setrecursionlimit(10 ** 9)
INF = float("inf")
IINF = 10 ** 18
MOD = 10 ** 9 + 7

# MOD = 998244353


DIGIT = (10 ** 18).bit_length()


def solve_f2(mat):
    # 掃き出し法
    rank = 0
    for col in range(mat.shape[1] - 1):
        if rank >= DIGIT:
            break
        row = mat[rank:, col].argmax() + rank
        if not mat[row, col]:
            continue
        pivot = mat[row].copy()
        mat[mat[:, col]] ^= pivot
        mat[row] = mat[rank]
        mat[rank] = pivot
        rank += 1

    if rank < DIGIT and mat[rank:].any():
        # 解無し
        return False
    else:
        return True


def solve(N, A, S):
    if S[-1] == '1':
        return 1

    # すべての1を、それより後ろの0で打ち消せればOK
    S = np.array(list(S), dtype=int) == 1
    A = np.array(A, dtype=int)

    zero_win = True
    for i in reversed(range(N)):
        if S[i]:
            a_mat = []
            vec = []
            for d in reversed(range(DIGIT)):
                a_mat.append(A[i + 1:][~S[i + 1:]] >> d & 1)
                vec.append([A[i] >> d & 1])
            mat = np.hstack((a_mat, vec)).astype(bool)
            zero_win &= solve_f2(mat)
    return int(not zero_win)


T = int(sys.stdin.buffer.readline())
for _ in range(T):
    N = int(sys.stdin.buffer.readline())
    A = list(map(int, sys.stdin.buffer.readline().split()))
    S = sys.stdin.buffer.readline().decode().rstrip()
    ans = solve(N, A, S)
    print(ans)


### FIXED CODE ###

import os

import sys
import numpy as np

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")

sys.setrecursionlimit(10 ** 9)
INF = float("inf")
IINF = 10 ** 18
MOD = 10 ** 9 + 7

# MOD = 998244353


DIGIT = (10 ** 18).bit_length()


def solve_f2(mat, last_col, rank):
    # 掃き出し法
    for col in range(last_col, mat.shape[1] - 1):
        if rank >= DIGIT:
            break
        last_col = col
        row = mat[rank:, col].argmax() + rank
        if not mat[row, col]:
            continue
        pivot = mat[row].copy()
        mat[mat[:, col]] ^= pivot
        mat[row] = mat[rank]
        mat[rank] = pivot
        rank += 1

    if rank < DIGIT and mat[rank:].any():
        # 解無し
        return False, last_col, rank
    else:
        return True, last_col, rank


def solve(N, A, S):
    if S[-1] == '1':
        return 1

    # すべての1を、それより後ろの0で打ち消せればOK
    S = (np.array(list(S), dtype=int) == 1)[::-1]
    A = np.array(A, dtype=int)[::-1]

    a_mat = []
    for d in reversed(range(DIGIT)):
        a_mat.append(A >> d & 1)
    mat = np.array(a_mat).astype(bool)

    rank = 0
    for col in range(N):
        if S[col]:
            # check
            if mat[rank:, col].any():
                # 1のかち
                return True
        if rank >= DIGIT:
            return False
        row = mat[rank:, col].argmax() + rank
        if not mat[row, col]:
            continue
        pivot = mat[row].copy()
        mat[mat[:, col]] ^= pivot
        mat[row] = mat[rank]
        mat[rank] = pivot
        rank += 1
    return False


T = int(sys.stdin.buffer.readline())
for _ in range(T):
    N = int(sys.stdin.buffer.readline())
    A = list(map(int, sys.stdin.buffer.readline().split()))
    S = sys.stdin.buffer.readline().decode().rstrip()
    ans = solve(N, A, S)
    print(int(ans))