#include using i64 = long long; std::vector a, b, t, pre; constexpr i64 mod = 998244353; i64 rec(int i, i64 x) { if (i == 0) return 1; if (i == 1) return x; if (pre[i] >= 0) return pre[i]; if (t[i] == 1) return (rec(a[i], x) + rec(b[i], x)) % mod; if (t[i] == 2) return a[i] * rec(b[i], x) % mod; return rec(a[i], x) * rec(b[i], x) % mod; } int main() { int n; std::cin >> n; a.resize(n + 1); b.resize(n + 1); t.resize(n + 1); pre.resize(n + 1); for (int i = 2; i <= n; i++) std::cin >> t[i] >> a[i] >> b[i]; int q; std::cin >> q; while (q--) { for (auto &e : pre) e = -1; i64 x; std::cin >> x; std::cout << rec(n, x) << std::endl; } return 0; }