#include <bits/stdc++.h>
using namespace std;
void io() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cout.precision(15);
}
vector<int> a;
vector<vector<int> > edges;
vector<int> divisors;
vector<int> count_divisors;
vector<int> ans;
vector<int> visited;
int gcd(int a, int b) {
  if (a < b) return gcd(b, a);
  if (b == 0) return a;
  return gcd(b, a % b);
}
void dfs1(int v) {
  visited[v] = 1;
  for (auto u : edges[v]) {
    if (!visited[u]) {
      ans[u] = gcd(a[u], ans[v]);
      dfs1(u);
    }
  }
}
void dfs2(int v, int d) {
  visited[v] = 1;
  for (int i = 0; i < divisors.size(); i++) {
    count_divisors[i] += (a[v] % divisors[i] == 0);
    if (count_divisors[i] >= d) ans[v] = max(ans[v], divisors[i]);
  }
  for (auto u : edges[v])
    if (!visited[u]) dfs2(u, d + 1);
  for (int i = 0; i < divisors.size(); i++)
    count_divisors[i] -= (a[v] % divisors[i] == 0);
}
int main() {
  io();
  int n;
  cin >> n;
  a.resize(n);
  edges.resize(n);
  ans.resize(n);
  visited.resize(n, false);
  for (int i = 0; i < n; i++) cin >> a[i];
  for (int i = 0; i < n - 1; i++) {
    int a, b;
    cin >> a >> b;
    a--;
    b--;
    edges[a].push_back(b);
    edges[b].push_back(a);
  }
  int p = a[0];
  a[0] = 0;
  ans[0] = 0;
  dfs1(0);
  ans[0] = p;
  for (int i = 0; i < n; i++) visited[i] = 0;
  for (int i = 1; i * i <= p; i++) {
    if (p % i == 0) {
      divisors.push_back(i);
      divisors.push_back(p / i);
      if (i * i == p) divisors.pop_back();
    }
  }
  sort(divisors.begin(), divisors.end());
  count_divisors.resize(divisors.size(), 0);
  dfs2(0, 0);
  for (int i = 0; i < n; i++) cout << ans[i] << " ";
  cout << endl;
}
