#include using namespace std; const long long MOD = 998244353; int main(){ int N; cin >> N; vector A(N); for (int i = 0; i < N; i++){ cin >> 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 B(N), C(N); for (int i = 0; i < N; i++){ B[i] = 1; for (int j = 0; j < A[i].size(); j++){ B[i] *= 10; B[i] %= MOD; } C[i] = stoll(A[i]) % MOD; } vector p(N, -1); vector> c(N); vector b; queue Q; Q.push(0); while (!Q.empty()){ int v = Q.front(); Q.pop(); b.push_back(v); for (int w : E[v]){ if (w != p[v]){ p[w] = v; c[v].push_back(w); Q.push(w); } } } reverse(b.begin(), b.end()); vector dp1(N, 0); vector dp2(N, 0); for (int v : b){ dp1[v] = 1; for (int w : c[v]){ dp1[v] += dp1[w]; dp2[v] += dp2[w]; dp2[v] %= MOD; } dp2[v] *= B[v]; dp2[v] %= MOD; dp2[v] += C[v] * dp1[v]; dp2[v] %= MOD; } reverse(b.begin(), b.end()); vector dp3(N, 0); dp3[0] = C[0]; for (int v : b){ long long sum = 0; for (int w : c[v]){ sum += dp2[w]; } if (v != 0){ sum += dp3[p[v]]; } sum %= MOD; for (int w : c[v]){ long long sum2 = (sum - dp2[w] + MOD) % MOD; sum2 *= B[v]; sum2 %= MOD; sum2 += C[v] * (N - dp1[w]); sum2 %= MOD; sum2 *= B[w]; sum2 %= MOD; sum2 += C[w] * (N - dp1[w] + 1); sum2 %= MOD; dp3[w] = sum2; } } long long ans = 0; for (int i = 0; i < N; i++){ ans += dp2[i] + dp3[i] - C[i] + MOD; ans %= MOD; } cout << ans << endl; }