#include <bits/stdc++.h>
using namespace std;
int n;
int a[200008];
int first[200008];
int nxt[200008 * 2];
int last[200008];
int to[200008 * 2];
int ans[200008];
int cnt = 0;
set<int> s[200008];
int gcd(int a, int b) {
  if (a == 0) return b;
  if (b == 0) return a;
  if (a % b == 0) return b;
  return gcd(b, a % b);
}
void addedge(int a, int b) {
  if (!first[a])
    first[a] = ++cnt;
  else
    nxt[last[a]] = ++cnt;
  last[a] = cnt;
  to[cnt] = b;
}
void dfs(int u, int fa, int now) {
  set<int>::iterator iter;
  if (u != 1)
    for (iter = s[fa].begin(); iter != s[fa].end(); iter++)
      s[u].insert(gcd(*iter, a[u]));
  s[u].insert(now);
  now = gcd(now, a[u]);
  s[u].insert(now);
  ans[u] = (*s[u].rbegin());
  for (int q = first[u]; q; q = nxt[q]) {
    if (to[q] != fa) {
      dfs(to[q], u, now);
    }
  }
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
  for (int i = 1; i < n; i++) {
    int a, b;
    scanf("%d%d", &a, &b);
    addedge(a, b);
    addedge(b, a);
  }
  dfs(1, -1, 0);
  for (int i = 1; i <= n; i++) {
    cout << ans[i] << ' ';
  }
  cout << endl;
  return 0;
}
