#include #include #include using namespace std; typedef long long int ll; const ll MOD = 998244353; struct func { int t, a, b; }; func F[51]; int n,q; ll fnct(ll ind, ll par) { if (ind == 0)return 1; if (ind == 1)return par; if (F[ind].t == 1)return (fnct(F[ind].a, par) + fnct(F[ind].b, par))%MOD; if (F[ind].t == 2)return (F[ind].a*fnct(F[ind].b, par)) % MOD; return (fnct(F[ind].a, par) * fnct(F[ind].b, par)) % MOD;; } int main() { cin >> n; for (int i = 2; i <= n; i++) { cin >> F[i].t >> F[i].a >> F[i].b; F[i].a %= MOD; F[i].b %= MOD; } cin >> q; for (int i = 0; i < q; i++) { int x; cin >> x; cout << fnct(n, x) << endl; } return 0; }