#include <bits/stdc++.h>
using namespace std;
int a[1000010], ans[1000010];
bool vis[1000100];
vector<vector<int> > g;
vector<int> di, cnt_div;
int gcd(int a, int b) {
  if (b == 0) return a;
  return gcd(b, a % b);
}
void dfs(int node, int par) {
  for (auto x : g[node]) {
    if (x != par) {
      ans[x] = gcd(ans[node], a[x]);
      dfs(x, node);
    }
  }
}
void divs() {
  for (int i = 1; i * i <= a[1]; i++) {
    if (a[1] % i == 0) {
      di.push_back(i);
      di.push_back(a[1] / i);
    }
    if (i * i == a[1]) di.pop_back();
  }
}
void dfs2(int node, int dis) {
  vis[node] = true;
  for (int i = 0; i < di.size(); i++) {
    if (a[node] % di[i] == 0) {
      cnt_div[i]++;
    }
    if (cnt_div[i] >= dis) {
      ans[node] = max(ans[node], di[i]);
    }
  }
  for (auto i : g[node]) {
    if (!vis[i]) {
      dfs2(i, dis + 1);
    }
  }
  for (int i = 0; i < di.size(); i++) {
    if (a[node] % di[i] == 0) {
      cnt_div[i]--;
    }
  }
}
int main() {
  int n, u, v;
  cin >> n;
  g.resize(n + 1);
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
  }
  for (int i = 0; i < n - 1; i++) {
    cin >> u >> v;
    g[u].push_back(v);
    g[v].push_back(u);
  }
  ans[1] = 0;
  dfs(1, 0);
  divs();
  sort(di.begin(), di.end());
  cnt_div.resize(di.size(), 0);
  ans[1] = a[1];
  dfs2(1, 0);
  for (int i = 1; i <= n; i++) {
    cout << ans[i] << " ";
  }
  return 0;
}
