# import sys; input = sys.stdin.buffer.readline # sys.setrecursionlimit(10**7) from collections import defaultdict con = 998244353; INF = float("inf") def getlist(): return list(map(int, input().split())) #処理内容 def main(): N = int(input()) ope = [] for i in range(N - 1): t, a, b = getlist() ope.append([t, a, b]) Q = int(input()) X = getlist() for q in range(Q): x = X[q] table = [0] * (N + 1) table[0] = 1 table[1] = x for i in range(N - 1): t, a, b = ope[i] if t == 1: table[i + 2] = (table[a] + table[b]) % con elif t == 2: table[i + 2] = (a * table[b]) % con else: table[i + 2] = (table[a] * table[b]) % con # print(table) print(table[-1]) if __name__ == '__main__': main()