import sys input = sys.stdin.readline N = int(input()) A = list(map(int, input().split())) G = [[] for i in range(N)] for i in range(N - 1): u, v = map(int, input().split()) u, v = u - 1, v - 1 G[u].append(v) G[v].append(u) mod = 998244353 def non_rec_dfs(s, G): N = len(G) stack = [s] par = [-1] * N sz = [1] * N dp = [0] * N ans = 0 while stack: u = stack.pop() if u >= 0: stack.append(~u) for v in G[u]: if v == par[u]: continue par[v] = u stack.append(v) else: u = ~u s1, s2 = 0, 0 for v in G[u]: if v == par[u]: continue sz[u] += sz[v] dp[u] += dp[v] * A[u] dp[u] %= mod s1 += dp[v] s2 += dp[v] ** 2 dp[u] += A[u] dp[u] %= mod ans += (s1 ** 2 - s2) // 2 * A[u] ans %= mod return (ans + sum(dp) - sum(A)) % mod print(non_rec_dfs(0, G))