#include <bits/stdc++.h>
using namespace std;
struct Edge {
  int to, next;
  Edge(int a = 0, int b = 0) { to = a, next = b; }
} l[200010 << 1];
int gcd(int x, int y) { return y == 0 ? x : gcd(y, x % y); }
int dp[200010][2], a[200010], head[200010], ans[200010], n, cnt, v[200010];
void add(int a, int b) {
  l[++cnt] = Edge(b, head[a]);
  head[a] = cnt;
}
void dfs(int u, int f, int d, int g) {
  ans[u] = g;
  int i;
  for (i = 1; i * i < a[u]; i++) {
    if (a[u] % i) continue;
    if (++v[a[u] / i] >= d) ans[u] = max(ans[u], a[u] / i);
    if (++v[i] >= d) ans[u] = max(ans[u], i);
  }
  if (i * i == a[u])
    if (++v[i] >= d) ans[u] = max(ans[u], i);
  for (i = head[u]; i; i = l[i].next) {
    int t = l[i].to;
    if (t == f) continue;
    dfs(t, u, d + 1, gcd(g, a[u]));
  }
  for (i = 1; i * i < a[u]; i++) {
    if (a[u] % i) continue;
    v[a[u] / i]--, v[i]--;
  }
  if (i * i == a[u]) v[i]--;
}
int main() {
  ios::sync_with_stdio(false);
  cin >> n;
  for (int i = 1; i <= n; i++) cin >> a[i];
  for (int i = 1; i < n; i++) {
    int x, y;
    cin >> x >> y;
    add(x, y), add(y, x);
  }
  dfs(1, 0, 0, 0);
  for (int i = 1; i <= n; i++) cout << ans[i] << " ";
}
