import sys sys.setrecursionlimit(2*10**5) import pypyjit pypyjit.set_param('max_unroll_recursion=-1') mod=998244353 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-=1 v-=1 g[u].append(v) g[v].append(u) ans=0 def dfs(p,prev): global ans sm1=0 sm2=0 for e in g[p]: if e==prev:continue v=dfs(e,p) sm1=(sm1+v)%mod sm2=(sm2+v*v)%mod ans=(ans+a[p]*sm1)%mod ans=(ans+a[p]*(sm1*sm1-sm2)*pow(2,mod-2,mod))%mod return a[p]*(1+sm1)%mod dfs(0,-1) print(ans)