#include <bits/stdc++.h>
using namespace std;
vector<int> adj[200009];
vector<int> dv;
int a[200005], ans[200005], idx[200005], vis[200005], x, y, n;
int gcd(int a, int b) {
  if (a < b) swap(a, b);
  if (b == 0) return a;
  return gcd(b, a % b);
}
void dfs(int v) {
  for (int i = 0; i < adj[v].size(); i++) {
    int el = adj[v][i];
    if (!vis[el]) {
      vis[el] = 1;
      ans[el] = gcd(ans[v], a[el]);
      dfs(el);
    }
  }
}
void cal(int v, int d) {
  for (int i = 0; i < dv.size(); i++) {
    idx[i] += (a[v] % dv[i] == 0);
    if (idx[i] >= d) {
      ans[v] = max(ans[v], dv[i]);
    }
  }
  for (int i = 0; i < adj[v].size(); i++) {
    int el = adj[v][i];
    if (!vis[el]) {
      vis[el] = 1;
      cal(el, d + 1);
    }
  }
  for (int i = 0; i < dv.size(); i++) {
    idx[i] -= (a[v] % dv[i] == 0);
  }
}
int main() {
  cin >> n;
  for (int i = 0; i < n; i++) cin >> a[i];
  for (int i = 0; i < n - 1; i++) {
    cin >> x >> y;
    x--, y--;
    adj[x].push_back(y);
    adj[y].push_back(x);
  }
  memset(ans, 0, sizeof(ans));
  memset(vis, 0, sizeof(vis));
  ans[0] = 0;
  vis[0] = 1;
  dfs(0);
  memset(vis, 0, sizeof(vis));
  for (int i = 1; i * i <= a[0]; i++) {
    if (a[0] % i == 0) {
      dv.push_back(i);
      dv.push_back(a[0] / i);
    }
    if (i * i == a[0]) dv.pop_back();
  }
  ans[0] = a[0];
  vis[0] = 1;
  cal(0, 0);
  for (int i = 0; i < n; i++) cout << ans[i] << " ";
  cout << endl;
  return 0;
}
