MOD = 998244353 N = int(input()) A = list(map(int, input().split())) UV = [list(map(int, input().split())) for _ in range(N - 1)] E = [[] for _ in range(N)] for u, v in UV: u -= 1 v -= 1 E[u].append(v) E[v].append(u) def dfs(x, p): global ans, X for y in E[x]: if y != p: X[y] += (X[x] + Y[x] + A[x]) * A[y] X[y] %= MOD dfs(y, x) Y[x] += (Y[y]+ A[y]) * A[x] Y[x] %= MOD #print(x,X,Y) X = [0] * N Y = [0] * N ans = 0 dfs(0, -1) #print(X,sum(X)) #print(Y,sum(Y)) print(sum(X) % MOD)