#include using namespace std; #define rep(i, a, n) for(int i=(a); i<(n); ++i) #define per(i, a, n) for(int i=(a); i>(n); --i) #define pb emplace_back #define mp make_pair #define clr(a, b) memset(a, b, sizeof(a)) #define all(x) (x).begin(),(x).end() #define lowbit(x) (x & -x) #define fi first #define se second #define lson o<<1 #define rson o<<1|1 #define gmid l[o]+r[o]>>1 using ll = long long; using ull = unsigned long long; using pii = pair; using pll = pair; using ui = unsigned int; constexpr int mod = 998244353; constexpr int inf = 0x3f3f3f3f; constexpr double EPS = 1e-8; const double PI = acos(-1.0); constexpr int N = 2e5 + 10; int T, n; bool f[N]; string g, op[N]; int pre[N], nxt[N], s[N]; bool calc(bool x, string &op, bool y){ if(op == "and") return x & y; if(op == "or") return x | y; if(op == "xor") return x ^ y; return x ? y : 1; } void add(int x, int v){ for(; x0; x-=lowbit(x)) ret += s[x]; return ret; } void _main(){ cin >> T; while(T--){ cin >> n; rep(i, 1, n + 1){ cin >> g; f[i] = g[0] == 'T'; } nxt[0] = 1; pre[n] = n - 1; rep(i, 1, n){ cin >> op[i]; pre[i] = i - 1; nxt[i] = i + 1; s[i] = 0; } rep(i, 1, n) add(i, 1); int x; rep(i, 1, n){ cin >> x; int low = 1, top = n - 1, mid, key = n - 1; while(low <= top){ mid = low + top >> 1; if(sum(mid) >= x){ key = min(key, mid); top = mid - 1; } else { low = mid + 1; } } x = key; add(x, -1); f[nxt[x]] = calc(f[x], op[x], f[nxt[x]]); nxt[pre[x]] = nxt[x]; pre[nxt[x]] = pre[x]; } cout << (f[n] ? "True" : "False") << '\n'; } } int main(){ ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); _main(); return 0; }