#include #include using namespace std; using namespace atcoder; typedef int64_t lint; #define rep(i, n) for(int i=0; i; using vvi = vector>; template inline void vin(vector& v) { rep(i, v.size()) cin >> v.at(i); } template inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; } template inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; } template inline void drop(T x) { cout << x << endl; exit(0); } template void vout(vector v) { rep(i, v.size()) { cout << v.at(i) << ' '; } cout << endl; } constexpr lint LINF = LLONG_MAX/2; int main() { lint T; cin >> T; rep(_, T) { lint N; cin >> N; vector v(N), w(N-1); vi Q(N-1); vin(v); vin(w); vin(Q); lint a=0, b=0, c=0, x, y, z; fenwick_tree fw(N); rep(i, N) fw.add(i, 1); rep(i, N-1) { lint ng = -1, mid, ok = N-2; while (abs(ok - ng) > 1) { mid = (ok + ng) / 2; x = fw.sum(0, mid+1); if (x >= Q[i]) ok = mid; else ng = mid; } z = ok; ng = -1, mid, ok = N-1; while (abs(ok - ng) > 1) { mid = (ok + ng) / 2; x = fw.sum(0, mid+1); if (x >= Q[i]+1) ok = mid; else ng = mid; } Q[i] = z; if (w[Q[i]] == "and") { if (v[Q[i]] == "False" || v[ok] == "False") { v[Q[i]] = "False"; v[ok] = "False"; } else { v[Q[i]] = "True"; v[ok] = "True"; } } else if (w[Q[i]] == "or") { if (v[Q[i]] == "True" || v[ok] == "True") { v[Q[i]] = "True"; v[ok] = "True"; } else { v[Q[i]] = "False"; v[ok] = "False"; } } else if (w[Q[i]] == "xor") { if (v[Q[i]] != v[ok]) { v[Q[i]] = "True"; v[ok] = "True"; } else { v[Q[i]] = "False"; v[ok] = "False"; } } else if (w[Q[i]] == "imp") { if (v[Q[i]] == "True") { v[Q[i]] = v[ok]; } else { v[Q[i]] = "True"; v[ok] = "True"; } } fw.add(Q[i], -1); } cout << v[Q[N-2]] << endl; } }