#include #include typedef struct tree { int v; struct tree *p; } tree; tree *get_root (tree *t) { if (t == NULL || t->p == NULL) { return t; } t->p = get_root(t->p); return t->p; } void add_segt (int *t, int idx, int val, int size) { idx = idx+size-1; t[idx] += val; while (idx > 0) { idx = (idx-1)/2; t[idx] += val; } return; } int sum_segt_rec (int *t, int a, int b, int k, int l, int r) { int ans = 0; if (r <= a || b <= l) { return 0; } if (a <= l && r <= b) { return t[k]; } ans = sum_segt_rec(t, a, b, 2*k+1, l, (l+r)/2); ans += sum_segt_rec(t, a, b, 2*k+2, (l+r)/2, r); return ans; } int sum_segt (int *t, int a, int b, int size) { return sum_segt_rec(t, a, b, 0, 0, size); } int main () { int t = 0; int n = 0; char x[6] = ""; char y[199999][4] = {}; int s[199999] = {}; int res = 0; tree tr[200000] = {}; int segt[524287] = {}; res = scanf("%d", &t); while (t > 0) { int size = 1; tree *rt = NULL; res = scanf("%d", &n); for (int i = 0; i < n; i++) { res = scanf("%s", x); if (x[0] == 'T') { tr[i].v = 1; tr[i].p = NULL; } else { tr[i].v = 0; tr[i].p = NULL; } } for (int i = 0; i < n-1; i++) { res = scanf("%s", y[i]); } for (int i = 0; i < n-1; i++) { res = scanf("%d", s+i); } while (size <= n) { size <<= 1; } for (int i = 0; i < 2*size-1; i++) { segt[i] = 0; } for (int i = 0; i < n; i++) { add_segt(segt, i, 1, size); } for (int i = 0; i < n-1; i++) { int idx[2] = { 0, n }; tree *rt1 = NULL; tree *rt2 = NULL; while (idx[1]-idx[0] > 1) { int nxt = (idx[0]+idx[1])/2; if (sum_segt(segt, 0, nxt, size) < s[i]) { idx[0] = nxt; } else { idx[1] = nxt; } } rt1 = get_root(tr+idx[0]); rt2 = get_root(tr+idx[1]); if (strcmp(y[idx[0]], "and") == 0) { rt1->v = rt1->v*rt2->v; } else if (strcmp(y[idx[0]], "or") == 0) { rt1->v = rt1->v*rt2->v+((rt1->v)^(rt2->v)); } else if (strcmp(y[idx[0]], "imp") == 0) { rt1->v = (1-rt1->v)*rt2->v+((1-rt1->v)^(rt2->v)); } else { rt1->v = (rt1->v)^(rt2->v); } rt2->p = rt1; add_segt(segt, idx[0], -1, size); } rt = get_root(tr); if (rt->v > 0) { printf("True\n"); } else { printf("False\n"); } t--; } return 0; }