#include #include using namespace std; using namespace atcoder; #define overload4(_1, _2, _3, _4, name, ...) name #define rep1(n) for(int i = 0; i < (int)(n); ++i) #define rep2(i, n) for(int i = 0; i < (int)(n); ++i) #define rep3(i, a, b) for(int i = (a); i < (int)(b); ++i) #define rep4(i, a, b, c) for(int i = (a); i < (int)(b); i += (c)) #define rep(...) overload4(__VA_ARGS__, rep4, rep3, rep2, rep1)(__VA_ARGS__) #define rrep(i,n) for(int i = (int)(n) - 1; i >= 0; --i) #define ALL(a) a.begin(), a.end() #define Sort(a) sort(a.begin(), a.end()) #define RSort(a) sort(a.rbegin(), a.rend()) typedef long long int ll; typedef unsigned long long ul; typedef long double ld; typedef vector vi; typedef vector vll; typedef vector vc; typedef vector vst; typedef vector vd; typedef vector vld; typedef pair P; template long long sum(const T& a){ return accumulate(a.begin(), a.end(), 0LL); } template auto min(const T& a){ return *min_element(a.begin(), a.end()); } template auto max(const T& a){ return *max_element(a.begin(), a.end()); } const long long MINF = 0x7fffffffffff; const long long INF = 0x1fffffffffffffff; const long long MOD = 1000000007; const long double EPS = 1e-9; const long double PI = acos(-1); 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 istream &operator>>(istream &is, pair &p){ is >> p.first >> p.second; return is; } template ostream &operator<<(ostream &os, const pair &p){ os << "(" << p.first << ", " << p.second << ")"; return os; } template istream &operator>>(istream &is, vector &v){ for(T &in : v) is >> in; return is; } template ostream &operator<<(ostream &os, const vector &v){ for(int i = 0; i < (int) v.size(); ++i){ os << v[i] << (i + 1 != (int) v.size() ? " " : ""); } return os; } template ostream &operator<<(ostream &os, const map &mp){ for(auto &[key, val] : mp){ os << key << ":" << val << " "; } return os; } template ostream &operator<<(ostream &os, const set &st){ auto itr = st.begin(); for(int i = 0; i < (int)st.size(); ++i){ os << *itr << (i + 1 != (int)st.size() ? " " : ""); itr++; } return os; } template ostream &operator<<(ostream &os, const multiset &st){ auto itr = st.begin(); for(int i = 0; i < (int)st.size(); ++i){ os << *itr << (i + 1 != (int)st.size() ? " " : ""); itr++; } return os; } template ostream &operator<<(ostream &os, queue q){ while(q.size()){ os << q.front() << " "; q.pop(); } return os; } template ostream &operator<<(ostream &os, deque q){ while(q.size()){ os << q.front() << " "; q.pop_front(); } return os; } template ostream &operator<<(ostream &os, stack st){ while(st.size()){ os << st.top() << " "; st.pop(); } return os; } template ostream &operator<<(ostream &os, priority_queue pq){ while(pq.size()){ os << pq.top() << " "; pq.pop(); } return os; } template inline T vin(T& vec, U n) { vec.resize(n); for(int i = 0; i < (int) n; ++i) cin >> vec[i]; return vec; } template inline void vout(T vec, string s = "\n"){ for(auto x : vec) cout << x << s; } template void in(T&... a){ (cin >> ... >> a); } void out(){ cout << '\n'; } template void out(const T& a, const Ts&... b){ cout << a; (cout << ... << (cout << ' ', b)); cout << '\n'; } template void inGraph(vector>& G, U n, U m, bool directed = false){ G.resize(n); for(int i = 0; i < m; ++i){ int a, b; cin >> a >> b; a--, b--; G[a].push_back(b); if(!directed) G[b].push_back(a); } } template struct SegmentTreeBeats{ int n, n0; vector max_v, smax_v, max_c; vector min_v, smin_v, min_c; vector sum; vector len, ladd, lval; void update_node_max(int k, T x) { sum[k] += (x - max_v[k]) * max_c[k]; if(max_v[k] == min_v[k]){ max_v[k] = min_v[k] = x; }else if(max_v[k] == smin_v[k]){ max_v[k] = smin_v[k] = x; }else{ max_v[k] = x; } if(lval[k] != INF && x < lval[k]){ lval[k] = x; } } void update_node_min(int k, T x) { sum[k] += (x - min_v[k]) * min_c[k]; if(max_v[k] == min_v[k]){ max_v[k] = min_v[k] = x; }else if(smax_v[k] == min_v[k]){ min_v[k] = smax_v[k] = x; }else{ min_v[k] = x; } if(lval[k] != INF && lval[k] < x){ lval[k] = x; } } void push(int k){ if(n0 - 1 <= k) return; if(lval[k] != INF){ updateall(2 * k + 1, lval[k]); updateall(2 * k + 2, lval[k]); lval[k] = INF; return; } if(ladd[k] != 0){ addall(2 * k + 1, ladd[k]); addall(2 * k + 2, ladd[k]); ladd[k] = 0; } if(max_v[k] < max_v[2 * k + 1]){ update_node_max(2 * k + 1, max_v[k]); } if(min_v[2 * k + 1] < min_v[k]){ update_node_min(2 * k + 1, min_v[k]); } if(max_v[k] < max_v[2 * k + 2]){ update_node_max(2 * k + 2, max_v[k]); } if(min_v[2 * k + 2] < min_v[k]){ update_node_min(2 * k + 2, min_v[k]); } } void update(int k){ sum[k] = sum[2 * k + 1] + sum[2 * k + 2]; if(max_v[2 * k + 1] < max_v[2 * k + 2]){ max_v[k] = max_v[2 * k + 2]; max_c[k] = max_c[2 * k + 2]; smax_v[k] = max(max_v[2 * k + 1], smax_v[2 * k + 2]); }else if(max_v[2 * k + 1] > max_v[2 * k + 2]){ max_v[k] = max_v[2 * k + 1]; max_c[k] = max_c[2 * k + 1]; smax_v[k] = max(smax_v[2 * k + 1], max_v[2 * k + 2]); }else{ max_v[k] = max_v[2 * k + 1]; max_c[k] = max_c[2 * k + 1] + max_c[2 * k + 2]; smax_v[k] = max(smax_v[2 * k + 1], smax_v[2 * k + 2]); } if(min_v[2 * k + 1] < min_v[2 * k + 2]){ min_v[k] = min_v[2 * k + 1]; min_c[k] = min_c[2 * k + 1]; smin_v[k] = min(smin_v[2 * k + 1], min_v[2 * k + 2]); }else if(min_v[2 * k + 1] > min_v[2 * k + 2]){ min_v[k] = min_v[2 * k + 2]; min_c[k] = min_c[2 * k + 2]; smin_v[k] = min(min_v[2 * k + 1], smin_v[2 * k + 2]); }else{ min_v[k] = min_v[2 * k + 1]; min_c[k] = min_c[2 * k + 1] + min_c[2 * k + 2]; smin_v[k] = min(smin_v[2 * k + 1], smin_v[2 * k + 2]); } } void _query_chmin(T x, int a, int b, int k, int l, int r) { if(b <= l || r <= a || max_v[k] <= x){ return; } if(a <= l && r <= b && smax_v[k] < x){ update_node_max(k, x); return; } push(k); _query_chmin(x, a, b, 2 * k + 1, l, (l + r) / 2); _query_chmin(x, a, b, 2 * k + 2, (l + r) / 2, r); update(k); } void _query_chmax(T x, int a, int b, int k, int l, int r) { if(b <= l || r <= a || x <= min_v[k]){ return; } if(a <= l && r <= b && x < smin_v[k]){ update_node_min(k, x); return; } push(k); _query_chmax(x, a, b, 2 * k + 1, l, (l + r) / 2); _query_chmax(x, a, b, 2 * k + 2, (l + r) / 2, r); update(k); } void addall(int k, T x) { max_v[k] += x; if(smax_v[k] != -INF) smax_v[k] += x; min_v[k] += x; if(smin_v[k] != INF) smin_v[k] += x; sum[k] += len[k] * x; if(lval[k] != INF){ lval[k] += x; }else{ ladd[k] += x; } } void updateall(int k, T x) { max_v[k] = x; smax_v[k] = -INF; min_v[k] = x; smin_v[k] = INF; max_c[k] = min_c[k] = len[k]; sum[k] = x * len[k]; lval[k] = x; ladd[k] = 0; } void _query_add(T x, int a, int b, int k, int l, int r) { if(b <= l || r <= a){ return; } if(a <= l && r <= b){ addall(k, x); return; } push(k); _query_add(x, a, b, 2 * k + 1, l, (l + r) / 2); _query_add(x, a, b, 2 * k + 2, (l + r) / 2, r); update(k); } void _query_update(T x, int a, int b, int k, int l, int r) { if(b <= l || r <= a){ return; } if(a <= l && r <= b){ updateall(k, x); return; } push(k); _query_update(x, a, b, 2 * k + 1, l, (l + r) / 2); _query_update(x, a, b, 2 * k + 2, (l + r) / 2, r); update(k); } T _query_max(int a, int b, int k, int l, int r) { if(b <= l || r <= a){ return -INF; } if(a <= l && r <= b){ return max_v[k]; } push(k); T lv = _query_max(a, b, 2 * k + 1, l, (l + r) / 2); T rv = _query_max(a, b, 2 * k + 2, (l + r) / 2, r); return max(lv, rv); } T _query_min(int a, int b, int k, int l, int r) { if(b <= l || r <= a){ return INF; } if(a <= l && r <= b){ return min_v[k]; } push(k); T lv = _query_min(a, b, 2 * k + 1, l, (l + r) / 2); T rv = _query_min(a, b, 2 * k + 2, (l + r) / 2, r); return min(lv, rv); } T _query_sum(int a, int b, int k, int l, int r) { if(b <= l || r <= a){ return 0; } if(a <= l && r <= b){ return sum[k]; } push(k); T lv = _query_sum(a, b, 2 * k + 1, l, (l + r) / 2); T rv = _query_sum(a, b, 2 * k + 2, (l + r) / 2, r); return lv + rv; } public: SegmentTreeBeats(int n) : n(n){ vector a; init(n, a); } SegmentTreeBeats(int n, vector &a) : n(n){ init(n, a); } void init(int n, vector &a){ max_v.assign(4 * n, 0), smax_v.assign(4 * n, 0), max_c.assign(4 * n, 0); min_v.assign(4 * n, 0), smin_v.assign(4 * n, 0), min_c.assign(4 * n, 0); sum.assign(4 * n, 0); len.assign(4 * n, 0), ladd.assign(4 * n, 0); lval.assign(4 * n, 0); n0 = 1; while(n0 < n) n0 <<= 1; for(int i = 0; i < 2 * n0; ++i) ladd[i] = 0, lval[i] = INF; len[0] = n0; for(int i = 0; i < n0 - 1; ++i) len[2 * i + 1] = len[2 * i + 2] = (len[i] >> 1); for(int i = 0; i < n; ++i){ max_v[n0 - 1 + i] = min_v[n0 - 1 + i] = sum[n0 - 1 + i] = (!a.empty() ? a[i] : 0); smax_v[n0 - 1 + i] = -INF; smin_v[n0 - 1 + i] = INF; max_c[n0 - 1 + i] = min_c[n0 - 1 + i] = 1; } for(int i = n; i < n0; ++i){ max_v[n0 - 1 + i] = smax_v[n0 - 1 + i] = -INF; min_v[n0 - 1 + i] = smin_v[n0 - 1 + i] = INF; max_c[n0 - 1 + i] = min_c[n0 - 1 + i] = 0; } for(int i = n0 - 2; i >= 0; --i){ update(i); } } // range minimize query void query_chmin(int a, int b, T x){ _query_chmin(x, a, b, 0, 0, n0); } // range maximize query void query_chmax(int a, int b, T x){ _query_chmax(x, a, b, 0, 0, n0); } // range add query void query_add(int a, int b, T x){ _query_add(x, a, b, 0, 0, n0); } // range update query void query_update(int a, int b, T x){ _query_update(x, a, b, 0, 0, n0); } // range minimum query T query_max(int a, int b){ return _query_max(a, b, 0, 0, n0); } // range maximum query T query_min(int a, int b){ return _query_min(a, b, 0, 0, n0); } // range sum query T query_sum(int a, int b){ return _query_sum(a, b, 0, 0, n0); } T get(int x){ return _query_sum(x, x + 1, 0, 0, n0); } }; ll t; void input(){ in(t); } void solve(){ ll n; in(n); vst x, y; vin(x, n); vin(y, n - 1); vll s; vin(s, n - 1); vll a(n), idx(n); rep(i, n){ if(x[i] == "True") a[i] = 1; else a[i] = 0; idx[i] = i; } SegmentTreeBeats seg(n, idx); rep(i, n - 1){ ll l = seg.get(s[i] - 1), r = seg.get(s[i]); string op = y[l]; if(op == "and"){ a[r] = a[l] & a[r]; }else if(op == "or"){ a[r] = a[l] | a[r]; }else if(op == "xor"){ a[r] = a[l] ^ a[r]; }else{ if(a[l] == 0){ a[r] = 1; } } seg.query_add(l, n, r - l); } if(a[seg.get(0)]){ out("True"); }else{ out("False"); } } int main(){ ios::sync_with_stdio(false); cin.tie(nullptr); cout << fixed << setprecision(20); input(); while(t--) solve(); }