#include <bits/stdc++.h>
using namespace std;
struct edge {
  int to, next;
} e[400040];
int eid = 0, head[200010];
void insert(int u, int v) {
  eid++;
  e[eid].to = v;
  e[eid].next = head[u];
  head[u] = eid;
}
int a[200010];
int n;
int fa[200010];
int dp[200010];
vector<int> v[200010];
int gcd(int a, int b) {
  if (b == 0) return a;
  return gcd(b, a % b);
}
void dfs(int x, int pre) {
  for (int i = head[x]; i + 1; i = e[i].next) {
    int k = e[i].to;
    if (k == pre) continue;
    dp[k] = gcd(dp[x], a[k]);
    v[k].push_back(dp[x]);
    for (int j = 0; j < v[x].size(); j++) {
      v[k].push_back(gcd(v[x][j], a[k]));
    }
    sort(v[k].begin(), v[k].end());
    v[k].erase(unique(v[k].begin(), v[k].end()), v[k].end());
    dfs(k, x);
  }
}
int main() {
  memset(head, -1, sizeof(head));
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
  }
  for (int i = 1; i < n; i++) {
    int x, y;
    cin >> x >> y;
    insert(x, y);
    insert(y, x);
    fa[y] = x;
  }
  fa[1] = 0;
  dp[1] = a[1];
  v[1].push_back(0);
  dfs(1, 0);
  for (int i = 1; i <= n; i++) dp[i] = max(dp[i], v[i].back());
  for (int i = 1; i <= n; i++) {
    cout << dp[i];
    if (i != n)
      cout << " ";
    else
      cout << endl;
  }
}
