#include using namespace std; struct iofast_t { iofast_t() { ios::sync_with_stdio(false); cin.tie(nullptr); } } iofast; struct uns_t {} uns; template auto vec(Element init, Head arg, Args ...args) { if constexpr (sizeof...(Args) == 0) return vector(arg, init); else return vector(arg, vec(init, args...)); } template auto vec(uns_t, Head arg, Args ...args) { return vec(Element(), arg, args...); } template auto distance(const Container &c, decltype(begin(c)) iter) { return distance(begin(c), iter); } template ::value_type>> auto isort(RIter first, RIter last, Compare comp = Compare()) { vector i(distance(first, last)); iota(begin(i), end(i), 0); sort(begin(i), end(i), [&](auto x, auto y) { return comp(*(first + x), *(first + y)); }); return i; } template typename, typename = void_t<>> struct detect : false_type {}; template typename Check> struct detect>> : true_type {}; template typename Check> constexpr inline bool detect_v = detect::value; template using has_member_sort = decltype(declval().sort()); template > auto sorted(Container c, Compare comp = Compare()) { if constexpr (detect_v) { c.sort(comp); return c; } else { sort(begin(c), end(c), comp); return c; } } template > auto uniqued(Container c, Compare comp = Compare()) { c.erase(unique(begin(c), end(c), comp), end(c)); return c; } template > T &chmin(T &l, T r, Compare &&f = less()) { return l = min(l, r, f); } template > T &chmax(T &l, T r, Compare &&f = less()) { return l = max(l, r, f); } template constexpr auto fix(F &&f) noexcept { return [f = std::tuple(std::forward(f))](auto &&...args) mutable { return std::get<0>(f)(fix(std::get<0>(f)), std::forward(args)...); }; } template struct binary_trie { static_assert(0 < Bits); constexpr static size_t bits = Bits; // O(1) binary_trie() noexcept: xor_all{ 0 }, root{} { } // O(1) // 0 <= v < 2^Bits void apply_xor(size_t v) noexcept { xor_all ^= v; } // O(1) size_t size() const noexcept { return root.count; } // O(Bits) // 0 <= v < 2^Bits size_t count(size_t v) const noexcept { return count_(v ^ xor_all); } // O(Bits) // 0 <= v < 2^Bits bool exist(size_t v) const noexcept { return exist_(v ^ xor_all); } // O(Bits) // 0 <= v < 2^Bits void insert(size_t v) { insert_(v ^ xor_all); } // O(Bits) // 0 <= v < 2^Bits void erase(size_t v) noexcept { erase_(v ^ xor_all); } // O(Bits) // 0 <= n < size(binary_trie) size_t nth_element(size_t n) const { if (size() <= n) { throw std::out_of_range("binary_trie"); } size_t path = 0; auto b = (size_t(1) << (Bits - 1)); const node *iter = &root; while (0 < b) { auto m = !!(xor_all & b); auto c = iter->c[m]; b >>= 1; path <<= 1; if (c != nullptr) { if (n < c->count) { iter = c; path |= 0; continue; } n -= c->count; } iter = iter->c[!m]; path |= 1; } return path; } // O(Bits) // 0 <= v < 2^Bits size_t lower_bound(size_t v) const noexcept { if (v == 0) { return 0; } return upper_bound(v - 1); } // O(Bits) // 0 <= v < 2^Bits size_t upper_bound(size_t v) const noexcept { auto b = (size_t(1) << (Bits - 1)); size_t sum = 0; const node *iter = &root; while (0 < b) { auto m = !!(xor_all & b); auto f = !!(v & b); auto c = iter->c[m]; if (c != nullptr && f) { sum += c->count; } auto d = iter->c[m ^ f]; if (d == nullptr) { return sum; } iter = d; b >>= 1; } sum += iter->count; return sum; } private: struct node { node() noexcept: count{ 0 }, c{ nullptr, nullptr } { } ~node() { if (c[0] != nullptr) delete c[0]; if (c[1] != nullptr) delete c[1]; } node *advance(bool f) { if (c[f] == nullptr) { c[f] = new node(); } return c[f]; } size_t count = 0; node *c[2]; }; size_t count_(size_t n) const noexcept { auto b = (size_t(1) << (Bits - 1)); const node *iter = &root; while (0 < b) { iter = iter->c[!!(n & b)]; if (iter == nullptr || iter->count == 0) { return 0; } b >>= 1; } return iter->count; } bool exist_(size_t n) const noexcept { return 0 < count_(n); } void insert_(size_t n) { auto b = (size_t(1) << (Bits - 1)); node *iter = &root; ++root.count; while (0 < b) { iter = iter->advance(!!(n & b)); ++iter->count; b >>= 1; } } void erase_(size_t n) noexcept { if (exist_(n)) { auto b = (size_t(1) << (Bits - 1)); node *iter = &root; --root.count; while (0 < b) { iter = iter->c[!!(n & b)]; --iter->count; b >>= 1; } } } size_t xor_all; node root; }; int main() { int t; cin >> t; while (t--) { int n; cin >> n; auto x = vec(uns, n); for (auto &v : x) { string s; cin >> s; v = (s[0] == 'T'); } auto y = vec(uns, n - 1); for (auto &v : y) { string s; cin >> s; if (s[0] == 'a') { v = 0; } if (s[0] == 'o') { v = 1; } if (s[0] == 'x') { v = 2; } if (s[0] == 'i') { v = 3; } } binary_trie<18> index; for (int i = 0; i < n; ++i) { index.insert(i); } for (int i = 1; i < n; ++i) { int s; cin >> s; --s; int l = index.nth_element(s); int r = index.nth_element(s + 1); if (y[l] == 0) { x[r] = x[l] & x[r]; } if (y[l] == 1) { x[r] = x[l] | x[r]; } if (y[l] == 2) { x[r] = x[l] ^ x[r]; } if (y[l] == 3) { x[r] = !x[l] | x[r]; } index.erase(l); } cout << (x[index.nth_element(0)] ? "True" : "False") << '\n'; } cout << flush; }