t=int(input()) for _ in range(t): n=int(input()) X=[True if _=="True" else False for _ in input().split()] Y=list(input().split()) S=list(map(int,input().split())) for s in S: y=Y[s-1] if y=='and': X=X[0:s-1] + [X[s-1] and X[s]] + X[s+1:] elif y=='or': X=X[0:s-1] + [X[s-1] or X[s]] + X[s+1:] elif y=='xor': X=X[0:s-1] + [X[s-1] != X[s]] + X[s+1:] elif y=='imp': X=X[0:s-1] + [X[s] if X[s-1] else True] + X[s+1:] Y=Y[0:s-1]+Y[s:] print(X[0])