/* -*- coding: utf-8 -*- * * 623.cc: No.623 fudan no modulus to tigau - yukicoder */ #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; /* constant */ const int MAX_N = 50; const int MOD = 998244353; /* typedef */ typedef long long ll; /* global variables */ int ts[MAX_N + 1], as[MAX_N + 1], bs[MAX_N + 1]; ll fs[MAX_N + 1]; /* subroutines */ /* main */ int main() { int n; scanf("%d", &n); for (int i = 2; i <= n; i++) scanf("%d%d%d", &ts[i], &as[i], &bs[i]); int q; scanf("%d", &q); while (q--) { int xi; scanf("%d", &xi); fs[0] = 1; fs[1] = xi; for (int i = 2; i <= n; i++) switch (ts[i]) { case 1: fs[i] = (fs[as[i]] + fs[bs[i]]) % MOD; break; case 2: fs[i] = (as[i] * fs[bs[i]]) % MOD; break; case 3: fs[i] = (fs[as[i]] * fs[bs[i]]) % MOD; break; } printf("%lld\n", fs[n]); } return 0; }