#include #if __has_include() #include #endif using namespace std; #define eb emplace_back #define LL(...) ll __VA_ARGS__;lin(__VA_ARGS__) #define RDVV(T,n,...) vec__VA_ARGS__;fe(refs(__VA_ARGS__),e)e.get().resizes(n);vin(__VA_ARGS__) #define VV(n,...) RDVV(ll,n,__VA_ARGS__) #define fo(i,...) for(auto[i,i##stop,i##step]=for_range(0,__VA_ARGS__);i(1,__VA_ARGS__);i>=i##stop;i+=i##step) #define fe(a,e,...) for(auto&&__VA_OPT__([)e __VA_OPT__(,__VA_ARGS__]):a) #define defpp templatevoid pp(const auto&...a){[[maybe_unused]]const char*c="";((o<(a...);} #define entry defpp void main();void main2();}int main(){my::io();my::main();}namespace my{ #define use_ml998244353 using ml=atcoder::modint998244353; namespace my{ auto&operator<<(ostream&o,const atcoder::modint998244353&x){return o<<(int)x.val();} void io(){cin.tie(nullptr)->sync_with_stdio(0);cout<constexpr auto for_range(T s,T b){T a=0;if(s)swap(a,b);return array{a-s,b,1-s*2};} templateconstexpr auto for_range(T s,T a,T b,T c=1){return array{a-s,b,(1-s*2)*c};} void lin(auto&...a){(cin>>...>>a);} void vin(auto&...a){fo(i,(a.size()&...))(cin>>...>>a[i]);} constexpr ll size10(auto x){x|=1;ll r=0;while(x>0)x/=10,++r;return r;} void dec(auto&...a){((--a),...);} templateusing pack_back_t=tuple_element_t>; } namespace my{ templateistream&operator>>(istream&i,vector&v){fe(v,e)i>>e;return i;} templateconstexpr int depth=0; templatestruct core_t_helper{using type=T;}; templateusing core_t=core_t_helper::type; templatestruct vec; templatestruct hvec_helper{using type=vec::type>;}; templatestruct hvec_helper<0,T>{using type=T;}; templateusing hvec=hvec_helper::type; templatestruct vec:vector{ static constexpr int D=depth+1; using C=core_t; using vector::vector; void resizes(const auto&...a){if constexpr(sizeof...(a)==D)*this=make(a...,C{});else{ }} static auto make(ll n,const auto&...a){ if constexpr(sizeof...(a)==1)return vec(n,array{a...}[0]); else { } } vec&operator--(){fe(*this,e)--e;return*this;} ll size()const{return vector::size();} auto&emplace_back(auto&&...a){vector::emplace_back(std::forward(a)...);return*this;} }; templaterequires(sizeof...(A)>=2)vec(const A&...a)->vec>>; } namespace my{ templatestruct edge_rev_index{ int from_,to_; WT wt_; int id_; int rev_idx_; edge_rev_index()=default; edge_rev_index(int from,int to,WT wt,int id,int rev_idx):from_(from),to_(to),wt_(wt),id_(id),rev_idx_(rev_idx){} }; } namespace my{ template&),S trans_vertex(S,ll),S e()>class RerootingDPTree{ public: ll n_; vec>>edges_; vec>dp_; vecres_; S operator[](ll i)const{return res_[i];} RerootingDPTree(ll n):n_(n),edges_(n),dp_(n),res_(n){} void add_edges(const vec&a,const vec&b){ fo(i,a.size()){ edges_[a[i]].eb(a[i],b[i],1,i,edges_[b[i]].size()); edges_[b[i]].eb(b[i],a[i],1,i,edges_[a[i]].size()-1); } } void build(){ auto dfs=[&](auto&&dfs,ll u,ll p)->S{ ll deg=edges_[u].size(); S cum=e(); dp_[u].resize(deg); fo(i,deg){ ll v=edges_[u][i].to_; if(v==p)continue; dp_[u][i]=trans_edge(dfs(dfs,v,u),edges_[u][i]); cum=op(cum,dp_[u][i]); } return trans_vertex(cum,u); }; dfs(dfs,0,-1); auto dfs2=[&](auto&&dfs2,ll u,ll p)->void{ ll deg=edges_[u].size(); vec dp_left(deg+1,e()),dp_right(deg,e()); fo(i,deg)dp_left[i+1]=op(dp_left[i],dp_[u][i]); of(i,deg,1)dp_right[i-1]=op(dp_[u][i],dp_right[i]); res_[u]=trans_vertex(dp_left[deg],u); fo(i,deg){ ll v=edges_[u][i].to_; if(v==p)continue; ll j=edges_[u][i].rev_idx_; dp_[v][j]=trans_edge(trans_vertex(op(dp_left[i],dp_right[i]),u),edges_[v][j]); dfs2(dfs2,v,u); } }; dfs2(dfs2,0,-1); } }; templateusing RerootingDPTreeMonoidAlias=RerootingDPTree; } namespace my{entry vecc; void main(){ LL(N); c.resize(N); lin(c); VV(N-1,a,b);dec(a,b); use_ml998244353 struct node{ using T=ml; struct S{ T val; ll size; S()=default; S(T val,ll size):val(val),size(size){} S&operator+=(const S&t){val+=t.val,size+=t.size;return*this;} S operator+(const S&t)const{return S{*this}+=t;} }; static S op(S a,S b){return a+b;}; static S trans_edge(S x,const edge_rev_index&){return x;}; static S trans_vertex(S x,ll u){ return{x.val*ml(10).pow(size10(c[u]))+c[u]*(x.size+1),x.size+1}; }; static S e(){return{0,0};} }; RerootingDPTreeMonoidAliasrt(N); rt.add_edges(a,b); rt.build(); ml ans=0; fo(i,N)ans+=rt[i].val; pp(ans); }}