#include <bits/stdc++.h>
using namespace std;
template <class A, class B>
bool mini(A &a, const B b) {
  return a > b ? (a = b, 1) : 0;
}
template <class A, class B>
bool maxi(A &a, const B b) {
  return a < b ? (a = b, 1) : 0;
}
const long long maxN = 2e5 + 5;
const long long maxA = 2e5 + 5;
long long n, x, y;
long long a[maxN], res[maxN], cnt[maxA];
vector<long long> adj[maxN];
vector<long long> forecast;
long long gcd(const long long a, const long long b) {
  if (b) return gcd(b, a % b);
  return a;
}
void dfs(const long long u = 1, const long long d = 1, const long long x = 0) {
  long long v;
  res[u] = x;
  for (vector<long long>::iterator i = forecast.begin(); i != forecast.end();
       i++) {
    v = *i;
    if (a[u] % v == 0) {
      cnt[v]++;
    }
    if (d - cnt[v] <= 1) maxi(res[u], v);
  }
  for (vector<long long>::iterator i = adj[u].begin(); i != adj[u].end(); i++) {
    v = *i;
    if (res[v]) continue;
    dfs(v, d + 1, gcd(a[v], x));
  }
  for (vector<long long>::iterator i = forecast.begin(); i != forecast.end();
       i++) {
    v = *i;
    if (a[u] % v == 0) cnt[v]--;
  }
}
void input() {
  cin >> n;
  for (long long i = (1), _b = (n); i <= (_b); i++) cin >> a[i];
  for (long long _ = (1), _b = (n); _ < (_b); _++) {
    cin >> x >> y;
    adj[x].push_back(y);
    adj[y].push_back(x);
  }
}
void solve() {
  for (long long i = (1), _b = (sqrt(a[1])); i <= (_b); i++)
    if (a[1] % i == 0) {
      forecast.push_back(i);
      if (a[1] != i * i) forecast.push_back(a[1] / i);
    }
  dfs();
  for (long long i = (1), _b = (n); i <= (_b); i++) cout << res[i] << ' ';
  cout << '\n';
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  input();
  solve();
  return 0;
}
