/** * author: Sooh * created: 20.02.2022 20:58:25 **/ #include using namespace std; #include using namespace atcoder; using mint = modint998244353; //using mint = modint1000000007; #pragma region template using ll = long long; template using V = vector; #define rep(i,n) for(int i=0;i void view(T e){std::cerr << e;} template void view(pair e){std::cerr << "("; view(e.fi); std::cerr << ", "; view(e.se); std::cerr << ")";} template void view(const set &st){ std::cerr << "\n";for(const auto& e : st){view(e); std::cerr << " ";}} template void view(const multiset &st){ std::cerr << "\n";for(const auto& e : st){view(e); std::cerr << " ";}} template void view(const map &mp){ std::cerr << "\n";for(const auto& [k, v]: mp){std::cerr << "("; view(k); std::cerr << ", "; view(v); std::cerr << ") ";}} template void view(const unordered_map &mp){ std::cerr << "\n";for(const auto& [k, v]: mp){std::cerr << "("; view(k); std::cerr << ", "; view(v); std::cerr << ") ";}} template void view(const std::vector& v){std::cerr << "\n";for(const auto& e : v){ view(e); std::cerr << " "; }} template void view(const std::vector >& vv){std::cerr << "\n";int cnt = 0;for(const auto& v : vv){cerr << cnt << "th : "; view(v); cnt++; std::cerr << std::endl;}} #else #define debug(var) 0 #endif ll power(ll a, ll p){ll ret = 1; while(p){if(p & 1){ret = ret * a;} a = a * a; p >>= 1;} return ret;} ll modpow(ll a, ll p, ll mod){ll ret = 1; while(p){assert(a < mod); if(p & 1){ret = ret * a % mod;} a = a * a % mod; p >>= 1;} return ret;} ll modinv(ll a, ll m) {ll b = m, u = 1, v = 0; while (b) {ll t = a / b ;a -= t * b; swap(a, b);u -= t * v; swap(u, v);}u %= m;if (u < 0) u += m;return u;} templatebool chmax(T &a, const K b) { if (abool chmin(T &a, const K b) { if (b> n; V t(n + 1), a(n + 1), b(n + 1); for(int i = 2; i <= n; i++) cin >> t[i] >> a[i] >> b[i]; V dp(51); V done(51); auto dfs = [&](auto&& self, int id, mint x)->mint{ if(id == 0) return 1; else if(id == 1) return x; else if(done[id]) return dp[id]; done[id] = 1; if(t[id] == 1) return dp[id] = self(self, a[id], x) + self(self, b[id], x); else if(t[id] == 2) return dp[id] = a[id] * self(self, b[id], x); else return dp[id] = self(self, a[id], x) * self(self, b[id], x); }; int q; cin >> q; while(q--){ dp.assign(51, 0); done.assign(51, 0); int x; cin >> x; cout << dfs(dfs, n, x).val() << '\n'; } }