#include <bits/stdc++.h>
using namespace std;
vector<vector<int> > G;
vector<int> visited, ans, gcd, val;
int mygcd(int a, int b) {
  if (b > a) swap(a, b);
  return (b == 0 ? a : mygcd(b, a % b));
}
void dfs(int u, int parent, set<int> pos) {
  visited[u] = 1;
  gcd[u] = val[u];
  set<int> mypos;
  for (int x : pos) mypos.insert(mygcd(x, val[u]));
  if (parent != -1) {
    gcd[u] = mygcd(gcd[u], gcd[parent]);
    mypos.insert(gcd[parent]);
  } else {
    mypos.insert(0);
  }
  ans[u] = *max_element(mypos.begin(), mypos.end());
  for (int v : G[u])
    if (!visited[v]) dfs(v, u, mypos);
}
int main() {
  int n;
  cin >> n;
  G.resize(n);
  visited = val = ans = gcd = vector<int>(n);
  for (int i = 0; i < n; i++) cin >> val[i];
  for (int i = 00; i < n - 1; i++) {
    int u, v;
    cin >> u >> v;
    G[--u].push_back(--v);
    G[v].push_back(u);
  }
  set<int> S;
  S.insert(0);
  dfs(0, -1, S);
  for (int i = 0; i < n; i++) {
    cout << ans[i] << " ";
  }
  cout << endl;
  return 0;
}
