#!/usr/bin/python2 # -*- coding: utf-8 -*- # † mod = 998244353 n = int(raw_input()) t = [None] * (n+1) a = [None] * (n+1) b = [None] * (n+1) # dp[i][d] := fi における x**d の係数 dp = [[0 for j in xrange(210)] for i in xrange(210)] dp[0][0] = 1 dp[1][1] = 1 for i in xrange(2, n+1): t[i], a[i], b[i] = map(int, raw_input().split()) if t[i] == 1: for d in xrange(55): dp[i][d] = dp[a[i]][d] + dp[b[i]][d] dp[i][d] %= mod elif t[i] == 2: for d in xrange(55): dp[i][d] = a[i] * dp[b[i]][d] dp[i][d] %= mod elif t[i] == 3: for d1 in xrange(103): for d2 in xrange(103): dp[i][d1+d2] += dp[a[i]][d1] * dp[b[i]][d2] dp[i][d1+d2] %= mod q = int(raw_input()) x = map(int, raw_input().split()) for i in xrange(q): res = 0 for d in xrange(200): res += dp[n][d] * pow(x[i], d, mod) res %= mod print res