#include #define F first #define S second using namespace std; inline int read(); void write(int); void writeln(int); const int P = 998244353; const int A = 2e5; int n; vector prime; void getprime() { prime.resize(A + 1); iota(prime.begin(), prime.end(), 0); for (int i = 2; i * i <= A; i++) if (prime[i] == i) for (int j = i * i; j <= A; j += i) if (prime[j] == j) prime[j] = i; return; } void fact(int x, unordered_map& f) { f.clear(); if (x == 1) return; while (x > 1) { int p = prime[x]; int cnt = 0; while (x % p == 0) x /= p, cnt++; f[p] = cnt; } } long long qpow(long long p, int e) { long long ret = 1; p %= P; while (e) { if (e & 1) ret = (ret * p) % P; p = (p * p) % P; e >>= 1; } return ret; } int main() { getprime(); n = read(); vector a(n + 1); for (int i = 1; i <= n; i++) a[i] = read(); vector > G(n + 1); for (int i = 0; i < n - 1; i++) { int u = read(), v = read(); G[u].push_back(v); G[v].push_back(u); } vector fa(n + 1, -1); queue que; que.push(1); fa[1] = 0; while (!que.empty()) { int u = que.front(); que.pop(); for (int v : G[u]) if (fa[v] == -1) fa[v] = u, que.push(v); } vector > cd(n + 1); for (int v = 2; v <= n; ++v) cd[fa[v]].push_back(v); vector > f(n + 1); for (int i = 1; i <= n; i++) fact(a[i], f[i]); vector cct(n + 1, 0); for (int u = 1; u <= n; u++) cct[u] = cd[u].size(); queue q; for (int u = 1; u <= n; u++) if (cct[u] == 0) q.push(u); vector ans(n + 1); while (!q.empty()) { int u = q.front(); q.pop(); for (int v : cd[u]) { if (f[u].size() < f[v].size()) swap(f[u], f[v]); for (const auto& kv : f[v]) { int p = kv.F, e = kv.S; auto it = f[u].find(p); if (it == f[u].end()) f[u][p] = e; else it->S = max(it->S, e); } f[v].clear(); } long long res = 1; for (const auto& kv : f[u]) res = res * qpow(kv.F, kv.S) % P; ans[u] = res; int p = fa[u]; if (p != 0) { if (--cct[p] == 0) q.push(p); } } for (int i = 1; i <= n; i++) printf("%d\n", ans[i]); return 0; } inline int read() { int res = 0, f = 1; char ch = getchar(); while (!(ch >= '0' && ch <= '9')) { if (ch == '-') f = -1; ch = getchar(); } while (ch >= '0' && ch <= '9') { res = (res << 1) + (res << 3) + (ch ^ 48); ch = getchar(); } return res * f; } void write(int x) { static int sta[35]; int top = 0; do { sta[top++] = x % 10; x /= 10; } while (x); while (top) putchar(sta[--top] ^ 48); } void writeln(int x) { write(x); putchar('\n'); }