#include <bits/stdc++.h>
using namespace std;
using pii = pair<int, int>;
const int N = 2e5 + 11;
int a[N], ans[N];
vector<int> e[N];
int gcd(int a, int b) {
  if (!b) return a;
  return gcd(b, a % b);
}
void dfs(int x, int p, int g, vector<pii> v) {
  int ig = gcd(g, a[x]);
  for (pii &p : v) p.second = gcd(p.second, a[x]);
  if (ig != g) v.push_back({g, 0});
  for (pii &p : v) ans[x] = max(ans[x], gcd(p.first, p.second));
  for (int i : e[x])
    if (i != p) dfs(i, x, ig, v);
}
int main() {
  int n;
  cin >> n;
  for (int i = 1; i <= n; i++) scanf("%d", a + i);
  for (int i = 1; i < n; i++) {
    int u, v;
    scanf("%d%d", &u, &v);
    e[u].push_back(v);
    e[v].push_back(u);
  }
  dfs(1, 0, 0, {{0, 0}});
  for (int i = 1; i <= n; i++) printf("%d\n", ans[i]);
}
