#include using namespace std; using ll = long long; #include using namespace atcoder; #define mint modint998244353 #define rep(i, n) for (int i = 0; i < n; i++) #define endl '\n' constexpr int inf = 100000; mint ten[11]; int al[inf]; ll a[inf]; mint xx1[inf], yy1[inf], xx2[inf], yy2[inf]; mint ans = 0; void f1(int to, int no, vector> &g) { xx1[to] = yy1[to] = 1; for (int i : g[to]) { if (i == no) continue; f1(i, to, g); xx1[to] += xx1[i]; yy1[to] += yy1[i]; } yy1[to] *= ten[al[to]]; } void f2(int to, int no, vector> &g) { mint xx = 1, yy = 1; for (int i : g[to]) { if (i == no) { xx += xx2[to]; yy += yy2[to]; continue; } xx += xx1[i]; yy += yy1[i]; } mint aans = 0; for (int i : g[to]) { if (i == no) { aans += yy2[to] * xx1[to]; continue; } xx2[i] = xx - xx1[i]; yy2[i] = (yy - yy1[i]) * ten[al[to]]; aans += yy1[i] * xx2[i]; f2(i, to, g); } ans += aans * a[to]; } int ff(ll n) { return n == 0 ? 0 : ff(n / 10) + 1; } int main() { cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(20); ten[0] = 1; for (int i = 1; i <= 10; i++) ten[i] = 10 * ten[i - 1]; int n; cin >> n; rep(i, n) { cin >> a[i]; al[i] = ff(a[i]); ans += n * a[i]; } vector> g(n); rep(i, n - 1) { int u, v; cin >> u >> v; u--, v--; g[u].push_back(v); g[v].push_back(u); } f1(0, -1, g); f2(0, -1, g); cout << ans.val() << endl; return 0; }