#include <bits/stdc++.h>
using namespace std;
const int N = 200000, M = 400000;
int head[N + 100], nxt[M + 100], pnt[M + 100];
int a[N + 100], ans[N + 100], dep[N + 100], cnt[N + 100];
int E;
void checkmax(int &x, int y) {
  if (y > x) x = y;
}
void init() {
  memset(head, -1, sizeof(head));
  memset(cnt, 0, sizeof(cnt));
  E = 0;
}
void add_edge(int u, int v) {
  pnt[E] = v;
  nxt[E] = head[u];
  head[u] = E++;
}
void dfs(int u, int f, int p) {
  int mx1 = 0, mx2 = 0;
  dep[u] = dep[f] + 1;
  for (int i = 1; i * i <= a[u]; i++) {
    if (a[u] % i == 0 && ++cnt[i] >= dep[u] - 1) {
      checkmax(mx1, i);
      if (cnt[i] == dep[u]) checkmax(mx2, i);
    }
    if (a[u] % i == 0 && a[u] / i != i && ++cnt[a[u] / i] >= dep[u] - 1) {
      checkmax(mx1, a[u] / i);
      if (cnt[a[u] / i] == dep[u]) checkmax(mx2, a[u] / i);
    }
  }
  checkmax(mx1, p);
  ans[u] = mx1;
  for (int i = head[u]; i != -1; i = nxt[i]) {
    int v = pnt[i];
    if (v == f) continue;
    dfs(v, u, mx2);
  }
  for (int i = 1; i * i <= a[u]; i++) {
    if (a[u] % i == 0) {
      cnt[i]--;
      if (i * i != a[u]) cnt[a[u] / i]--;
    }
  }
}
int main() {
  int n, i;
  scanf("%d", &n);
  init();
  for (i = 1; i <= n; i++) scanf("%d", &a[i]);
  for (i = 1; i <= n - 1; i++) {
    int u, v;
    scanf("%d%d", &u, &v);
    add_edge(u, v);
    add_edge(v, u);
  }
  ans[1] = a[1];
  dfs(1, 0, 0);
  for (i = 1; i <= n; i++) printf("%d ", ans[i]);
  printf("\n");
  return 0;
}
