#include #include using namespace std; using namespace atcoder; using mint = modint998244353; int main() { int N; cin >> N; vector A(N); for (int i = 0; i < N; i++) { cin >> A[i]; } vector B(N), C(N); for (int i = 0; i < N; i++) { B[i] = 1; for (int j = 0; j < (int) A[i].size(); j++) { B[i] *= 10; } C[i] = mint(stoll(A[i])); } vector> E(N); for (int i = 0; i < N - 1; i++) { int u, v; cin >> u >> v; u--; v--; E[u].push_back(v); E[v].push_back(u); } vector> c(N); vector p(N, -1); vector bfs; queue Q; Q.push(0); while (!Q.empty()) { int v = Q.front(); Q.pop(); bfs.push_back(v); for (int w : E[v]) { if (w != p[v]) { p[w] = v; c[v].push_back(w); Q.push(w); } } } reverse(bfs.begin(), bfs.end()); vector dp1(N); vector dp2(N); for (int v : bfs) { dp1[v]++; for (int w : c[v]) { dp1[v] += dp1[w]; dp2[v] += dp2[w]; } dp2[v] *= B[v]; dp2[v] += C[v] * dp1[v]; } reverse(bfs.begin(), bfs.end()); vector dp3(N);//dp3[0] = 0; for (int v : bfs) { mint sum = 0; for (int w : c[v]) { sum += dp2[w]; } for (int w : c[v]) { mint sum2 = sum; sum2 -= dp2[w]; sum2 *= B[v]; sum2 += C[v] * (dp1[v] - dp1[w]); sum2 += dp3[v]; sum2 *= B[w]; sum2 += C[w] * (N - dp1[w]); dp3[w] = sum2; } } mint ans = 0; for (int i = 0; i < N; i++) { ans += dp2[i] + dp3[i]; } cout << ans.val() << endl; }