import sys from functools import partial # import pypyjit # pypyjit.set_param('max_unroll_recursion = -1') sys.setrecursionlimit(500005) stdin = sys.stdin ns = lambda: stdin.readline().strip() ni = lambda: int(ns()) na = lambda: list(map(int, stdin.readline().split())) nz = lambda: list(map(lambda x: int(x)-1, stdin.readline().split())) # 遅い printa = partial(print, sep="\n") # printa(*A) で各要素を改行して出力 mod = 1000000007 # 998244353 inf = 10 ** 18 # @maspy / Segment Tree のお勉強(1) # https://maspypy.com/segment-tree-%E3%81%AE%E3%81%8A%E5%8B%89%E5%BC%B71 from operator import add class SegTree: X_unit = 0 X_f = add def __init__(self, N): self.N = N self.X = [self.X_unit] * (N + N) def build(self, seq): for i, x in enumerate(seq, self.N): self.X[i] = x for i in range(self.N - 1, 0, -1): self.X[i] = self.X_f(self.X[i << 1], self.X[i << 1 | 1]) def set_val(self, i, x): i += self.N self.X[i] = x while i > 1: i >>= 1 self.X[i] = self.X_f(self.X[i << 1], self.X[i << 1 | 1]) def sub_val(self, i, x): i += self.N self.X[i] -= x while i > 1: i >>= 1 self.X[i] = self.X_f(self.X[i << 1], self.X[i << 1 | 1]) def fold(self, L, R): """半開区間 [L, R)""" L += self.N R += self.N vL = self.X_unit vR = self.X_unit while L < R: if L & 1: vL = self.X_f(vL, self.X[L]) L += 1 if R & 1: R -= 1 vR = self.X_f(self.X[R], vR) L >>= 1 R >>= 1 return self.X_f(vL, vR) def find_l(self, k): id = 1 while id < self.N: if self.X[id << 1] >= k: id <<= 1 else: k -= self.X[id << 1] id = id << 1 | 1 return id - self.N def debug(self): print(self.X[self.N:]) def set_size(k): ret = 1 while k >= 2: k //= 2 ret += 1 return pow(2, ret) def cal(x, y, o): if o == "a": return x & y elif o == "o": return x | y elif o == "x": return x ^ y else: return (not x) | y def solve(): N = ni() N = set_size(N) Xseg = SegTree(N) Xseg.build([1] * N) Yseg = SegTree(N) Yseg.build([1] * N) X = [1 if i == "True" else 0 for i in ns().split()] Y = list(ns().split()) S = na() for s in S: yid = Yseg.find_l(s) Yseg.sub_val(yid, 1) op = Y[yid][0] xidl = Xseg.find_l(s) xidr = Xseg.find_l(s+1) Xseg.sub_val(xidr, 1) # print(op, xidl, xidr, X) X[xidl] = cal(X[xidl], X[xidr], op) print("True" if X[0] else "False") T = ni() for _ in range(T): solve()