#include <bits/stdc++.h>
using namespace std;
const int boss = 2e5;
vector<int> lj[boss + 10];
set<int> s[boss + 10];
int n, a[boss + 10];
int gcd(int a, int b) { return !b ? a : gcd(b, a % b); }
void dfs(int u, int fa, int r) {
  for (set<int>::iterator i = s[fa].begin(); i != s[fa].end(); i++)
    s[u].insert(gcd(*i, a[u]));
  s[u].insert(r);
  for (int i : lj[u])
    if (i != fa) dfs(i, u, gcd(r, a[u]));
}
int main() {
  int i, u, v;
  scanf("%d", &n);
  for (i = 1; i <= n; i++) scanf("%d", &a[i]);
  for (i = 1; i < n; i++) {
    scanf("%d%d", &u, &v);
    lj[u].push_back(v);
    lj[v].push_back(u);
  }
  s[0].insert(0), dfs(1, 0, 0);
  for (i = 1; i <= n; i++) printf("%d ", *s[i].rbegin());
}
