#int-input def II() -> int : return int(input()) def MI() -> int : return map(int, input().split()) class fenwick_tree(): n=1 data=[0 for i in range(n)] def __init__(self,N): self.n=N self.data=[0 for i in range(N)] def add(self,p,x): assert 0<=p0): s+=self.data[r-1] r-=r&-r return s class dsu(): n=1 parent_or_size=[-1 for i in range(n)] def __init__(self,N): self.n=N self.parent_or_size=[-1 for i in range(N)] def merge(self,a,b): assert 0<=a0: result2.append(result[i]) return result2 n = II() a = list(MI()) edge = [set() for i in range(n)] for i in range(n-1): u,v = MI() u -= 1 v -= 1 edge[u].add(v) edge[v].add(u) mod = 998244353 def DFS_par(edge): #親の情報をうまく持つDFS ans = 0 cnt = [0]*len(edge) #親を持ちながら非再帰DFS n = len(edge) st = [(0,None,0)] while st: # print(cnt) now,par,t = st.pop() if t == 0: st.append((now,par,1)) #行きがけ for chi in edge[now]: if chi != par: st.append((chi,now,0)) else: ans += cnt[now]*a[now]%mod if par != None: tmp = a[now]*(cnt[now]+1)%mod ans += cnt[par]*a[par]*tmp%mod cnt[par] += tmp pass #帰りがけ return ans print(DFS_par(edge)%mod)