import sys read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines import numpy as np N = int(readline()) data = list(map(int,read().split())) TAB = data[:N+N+N-3] X = np.array(data[N+N+N-2:]) MOD = 998244353 F = [None] * (N+1) F[0] = np.ones_like(X) F[1] = X.copy() for n in range(2,N+1): t,a,b = data[3*n-6:3*n-3] if t == 1: F[n] = (F[a] + F[b]) % MOD elif t == 2: F[n] = a * F[b] % MOD else: F[n] = F[a] * F[b] % MOD print(' '.join(F[N].astype(str)))