#include <bits/stdc++.h>
using namespace std;
const int maxn = 200000 + 10;
struct node {
  int next, to;
} e[maxn * 2];
int head[maxn * 2];
int a[maxn];
set<int> G[maxn];
int ans[maxn];
int cnt;
int gcd(int a, int b) {
  if (!b) return a;
  return gcd(b, a % b);
}
void init() {
  memset(head, 0, sizeof(head));
  cnt = 0;
}
void add(int u, int t) {
  e[++cnt].next = head[u];
  e[cnt].to = t;
  head[u] = cnt;
}
void dfs(int u, int fa) {
  for (int i = head[u]; i != 0; i = e[i].next) {
    int v = e[i].to;
    if (v == fa) continue;
    ans[v] = gcd(ans[u], a[v]);
    G[v].insert(ans[u]);
    for (set<int>::iterator it = G[u].begin(); it != G[u].end(); it++) {
      G[v].insert(gcd(*it, a[v]));
    }
    dfs(v, u);
  }
}
int main() {
  int n;
  init();
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
  for (int i = 0; i < n - 1; i++) {
    int u, v;
    scanf("%d%d", &u, &v);
    add(u, v);
    add(v, u);
  }
  ans[1] = a[1];
  G[1].insert(0);
  dfs(1, 0);
  for (int i = 1; i <= n; i++) {
    set<int>::iterator it = G[i].end();
    it--;
    ans[i] = max(ans[i], *it);
  }
  for (int i = 1; i <= n; i++) {
    if (i == 1)
      printf("%d", ans[i]);
    else
      printf(" %d", ans[i]);
  }
  return 0;
}
