import sys sys.setrecursionlimit(10**7) from functools import lru_cache mod = 998244353 @lru_cache(maxsize=None) def f(t, i, a, b, x): if i == 0: return 1 if i == 1: return x if t == 1: return (f(T[a], a, A[a], B[a], x) + f(T[b], b, A[b], B[b], x)) % mod elif t == 2: return a * f(T[b], b, A[b], B[b], x) % mod else: return (f(T[a], a, A[a], B[a], x) * f(T[b], b, A[b], B[b], x)) % mod N = int(input()) T, A, B = [0] * 2, [0] * 2, [0] * 2 for i in range(N - 1): t, a, b = map(int, input().split()) T.append(t) A.append(a) B.append(b) Q = int(input()) X = list(map(int, input().split())) for x in X: print(f(T[N], N, A[N], B[N], x))