#include <bits/stdc++.h>
using namespace std;
struct data {
  int nex, to;
} e[200010 * 2];
int head[200010], edge = 0, a[200010], ans[200010];
set<int> st[200010];
set<int>::iterator it;
int gcd(int x, int y) { return y == 0 ? x : gcd(y, x % y); }
inline void add(int from, int to) {
  e[++edge].nex = head[from];
  e[edge].to = to;
  head[from] = edge;
}
void dfs(int x, int fa, int GCD) {
  ans[x] = *--st[x].end();
  for (int i = head[x]; i; i = e[i].nex) {
    int v = e[i].to;
    if (v == fa) continue;
    for (it = st[x].begin(); it != st[x].end(); it++)
      st[v].insert(gcd(a[v], *it));
    st[v].insert(GCD);
    dfs(v, x, gcd(GCD, a[v]));
  }
}
int main() {
  int n, x, y;
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
  for (int i = 1; i < n; i++) scanf("%d%d", &x, &y), add(x, y), add(y, x);
  st[1].insert(a[1]), st[1].insert(0);
  dfs(1, 0, a[1]);
  for (int i = 1; i <= n; i++) printf("%d ", ans[i]);
  return 0;
}
