#include <bits/stdc++.h>
using namespace std;
const int SIZ = 2e5 + 2007;
int N;
int S[SIZ];
struct tgno {
  int v;
  tgno* n;
} POOL[SIZ << 1], *Head[SIZ];
int ppos;
void _add(int u, int v) {
  POOL[ppos].v = v;
  POOL[ppos].n = Head[u];
  Head[u] = &POOL[ppos++];
}
void addEdge(int u, int v) { _add(u, v), _add(v, u); }
int gcd(int x, int y) { return y ? gcd(y, x % y) : x; }
vector<int> factorize(int x) {
  vector<int> ret;
  for (int i = 1; i * i <= x; i++) {
    if (x % i == 0) {
      ret.push_back(i);
      if (x != i * i) ret.push_back(x / i);
    }
  }
  sort(ret.begin(), ret.end());
  return ret;
}
vector<int> fac;
int ans[SIZ];
void dfs1(int u = 1, int pre = 0) {
  typedef tgno* It;
  ans[u] = gcd(ans[pre], S[u]);
  for (It i = Head[u]; i; i = i->n) {
    if (i->v != pre) dfs1(i->v, u);
  }
}
int cnt[SIZ];
void dfs2(int u = 1, int pre = 0, int dd = 1) {
  int _ = fac.size();
  for (int i = 0; i < _; i++) {
    cnt[i] += (S[u] % fac[i] == 0);
    if (cnt[i] >= dd - 1) ans[u] = max(ans[u], fac[i]);
  }
  typedef tgno* It;
  for (It i = Head[u]; i; i = i->n) {
    if (i->v != pre) dfs2(i->v, u, dd + 1);
  }
  for (int i = 0; i < _; i++) cnt[i] -= (S[u] % fac[i] == 0);
}
int main() {
  scanf("%d", &N);
  for (int i = 1; i <= N; i++) scanf("%d", &S[i]);
  for (int i = 1, u, v; i < N; i++) {
    scanf("%d %d", &u, &v);
    addEdge(u, v);
  }
  int p = S[1];
  S[1] = ans[1] = 0;
  dfs1();
  S[1] = p;
  fac = factorize(p);
  dfs2();
  for (int i = 1; i <= N; i++) printf("%d ", ans[i]);
  puts("");
}
