#include <bits/stdc++.h>
using namespace std;
const int INF = 2000 * 1000 * 1000;
const long long LLINF = 1ll << 53;
template <class T>
void relaxmax(T& r, T v) {
  r = max(r, v);
}
template <class T>
void relaxmin(T& r, T v) {
  r = min(r, v);
}
const int N = 200 * 1000;
vector<int> adj[N];
map<pair<int, pair<int, int> >, bool> m;
int ans[N];
int a[N];
int n;
int gcd(int a, int b) { return b == 0 ? a : gcd(b, a % b); }
void dfs(int u, int val, bool used = false, int p = -1) {
  pair<int, pair<int, int> > idx = {u, {val, used}};
  if (m[idx]) return;
  m[idx] = true;
  relaxmax(ans[u], val);
  for (int v : adj[u])
    if (v != p) {
      dfs(v, gcd(val, a[v]), used, u);
      if (!used) dfs(v, val, true, u);
    }
}
int main() {
  scanf("%d", &n);
  for (int i = 0; i < n; ++i) scanf("%d", &a[i]);
  for (int i = 0; i < n - 1; ++i) {
    int u, v;
    scanf("%d%d", &u, &v);
    u--;
    v--;
    adj[u].push_back(v);
    adj[v].push_back(u);
  }
  dfs(0, 0, true);
  dfs(0, a[0], false);
  for (int i = 0; i < n; ++i) printf("%d ", ans[i]);
  puts("");
  return 0;
}
