#include using namespace std; typedef long long ll; typedef pair PII; const int MM = 998244353; const double eps = 1e-8; const int MAXN = 2e6 + 10; int n, m; void prework(){ } void read(){ } ll t[MAXN], a[MAXN], b[MAXN]; ll ans[MAXN]; void gao(){ ll x; cin >> x; ans[0] = 1; ans[1] = x; for (int i = 2; i <= n; i++){ if (t[i] == 1){ ans[i] = (ans[a[i]] + ans[b[i]] ) % MM; } else if (t[i] == 2){ ans[i] = (a[i] * ans[b[i]]) % MM; } else { ans[i] = (ans[a[i]] * ans[b[i]]) % MM; } } cout << ans[n] << endl; } void solve(int casi){ // cout << "Case #" << casi << ": "; cin >> n; for (int i = 2; i <= n; i++) cin >> t[i] >> a[i] >> b[i]; cin >> m; for (int i = 1; i <= m; i++) gao(); } void printans(){ } int main(){ // std::ios::sync_with_stdio(false); prework(); int T = 1; // cin>>T; for(int i = 1; i <= T; i++){ read(); solve(i); printans(); } return 0; }