Buggy python submission (verdict: Runtime Error):
3
2
1 2
10
2
1 1
10
6
2 3 4 5 6 7
111000

Fixed submission:
def gauss_jordan(bs):
    rank = 0
    pivot_cols = []
    for col in reversed(range(61)):
        pivot = -1
        for i,row in enumerate(bs[rank:]):
            if row&(1<<col):
                pivot = rank+i
                break
        if pivot < 0: continue
        pivot_cols.append(col)
        bs[pivot],bs[rank] = bs[rank],bs[pivot]
        for i,row in enumerate(bs):
            if i != rank and row&(1<<col):
                bs[i] ^= bs[rank]
        rank += 1
    return bs

def solve():
    N = int(input())
    A = list(map(int,input().split()))
    S = input()
    bs = []
    for a,s in zip(A[::-1],S[::-1]):
        x = a
        for b in bs:
            x = min(x, x^b)
        if x:
            if s=='0':
                bs.append(x)
                bs = gauss_jordan(bs)
            else:
                return 1
    return 0

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

Buggy python submission (verdict: Time Limit Exceeded):
import sys
sys.setrecursionlimit(10**8)
from functools import lru_cache

T = int(input())
for _ in range(T):
    N = int(input())
    A = list(map(int,input().split()))
    S = input()
    if S[-1]=='1':
        print(1)
        continue

    @lru_cache(maxsize=10**7)
    def rec(i,x):
        if i==N:
            return 1 if x>0 else 0
        if S[i]=='0':
            a = rec(i+1,x^A[i])
            if a == 0: ret = 0
            else:
                b = rec(i+1,x)
                ret = b
        else:
            a = rec(i+1,x^A[i])
            if a == 1: ret = 1
            else:
                b = rec(i+1,x)
                ret = b
        return ret
    print(rec(0,0))

Fixed submission:
def gauss_jordan(bs):
    rank = 0
    pivot_cols = []
    for col in reversed(range(61)):
        pivot = -1
        for i,row in enumerate(bs[rank:]):
            if row&(1<<col):
                pivot = rank+i
                break
        if pivot < 0: continue
        pivot_cols.append(col)
        bs[pivot],bs[rank] = bs[rank],bs[pivot]
        for i,row in enumerate(bs):
            if i != rank and row&(1<<col):
                bs[i] ^= bs[rank]
        rank += 1
    return bs

def solve():
    N = int(input())
    A = list(map(int,input().split()))
    S = input()
    bs = []
    for a,s in zip(A[::-1],S[::-1]):
        x = a
        for b in bs:
            x = min(x, x^b)
        if x:
            if s=='0':
                bs.append(x)
                bs = gauss_jordan(bs)
            else:
                return 1
    return 0

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

Buggy python submission (verdict: Time Limit Exceeded):
import sys
sys.setrecursionlimit(10**8)
from functools import lru_cache

T = int(input())
for _ in range(T):
    N = int(input())
    A = list(map(int,input().split()))
    S = input()

    @lru_cache(maxsize=10**7)
    def rec(i,x):
        if i==N:
            return 1 if x>0 else 0
        if S[i]=='0':
            a = rec(i+1,x)
            if a == 0: ret = 0
            else:
                b = rec(i+1,x^A[i])
                ret = b
        else:
            a = rec(i+1,x)
            if a == 1: ret = 1
            else:
                b = rec(i+1,x^A[i])
                ret = b
        return ret
    print(rec(0,0))

Fixed submission:
def gauss_jordan(bs):
    rank = 0
    pivot_cols = []
    for col in reversed(range(61)):
        pivot = -1
        for i,row in enumerate(bs[rank:]):
            if row&(1<<col):
                pivot = rank+i
                break
        if pivot < 0: continue
        pivot_cols.append(col)
        bs[pivot],bs[rank] = bs[rank],bs[pivot]
        for i,row in enumerate(bs):
            if i != rank and row&(1<<col):
                bs[i] ^= bs[rank]
        rank += 1
    return bs

def solve():
    N = int(input())
    A = list(map(int,input().split()))
    S = input()
    bs = []
    for a,s in zip(A[::-1],S[::-1]):
        x = a
        for b in bs:
            x = min(x, x^b)
        if x:
            if s=='0':
                bs.append(x)
                bs = gauss_jordan(bs)
            else:
                return 1
    return 0

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