#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-1); rep(i, N-1) 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; } Q[i] = ok; if (w[Q[i]] == "and") { if (v[Q[i]] == "False" || v[Q[i]+1] == "False") { v[Q[i]] = "False"; v[Q[i]+1] = "False"; } else { v[Q[i]] = "True"; v[Q[i]+1] = "True"; } } else if (w[Q[i]] == "or") { if (v[Q[i]] == "True" || v[Q[i]+1] == "True") { v[Q[i]] = "True"; v[Q[i]+1] = "True"; } else { v[Q[i]] = "False"; v[Q[i]+1] = "False"; } } else if (w[Q[i]] == "xor") { if (v[Q[i]] != v[Q[i]+1]) { v[Q[i]] = "True"; v[Q[i]+1] = "True"; } else { v[Q[i]] = "False"; v[Q[i]+1] = "False"; } } else if (w[Q[i]] == "imp") { if (v[Q[i]] == "True") { v[Q[i]] = v[Q[i]+1]; } else { v[Q[i]] = "True"; v[Q[i]+1] = "True"; } } fw.add(Q[i], -1); } cout << v[Q[N-2]] << endl; } }