#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f;
const long long INFF = 0x3f3f3f3f3f3f3f3fll;
const long long M = 1e9 + 7;
const long long maxn = 2e5 + 7;
const double eps = 0.00000001;
long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }
template <typename T>
inline T abs(T a) {
  return a > 0 ? a : -a;
}
template <typename T>
inline T powMM(T a, T b) {
  T ret = 1;
  for (; b; b >>= 1ll, a = a * a % M)
    if (b & 1) ret = 1ll * ret * a % M;
  return ret;
}
int n, m, t;
int i;
vector<int> edge[maxn];
vector<int> DIV;
int val[maxn];
int cnt[maxn];
int ans[maxn];
void dfs(int x, int fa, int VAL) {
  int i;
  for (i = 0; i < DIV.size(); i++)
    if (val[x] % DIV[i] != 0) cnt[i]++;
  for (int v : edge[x]) {
    if (v == fa) continue;
    if (fa == 0)
      dfs(v, x, val[v]);
    else
      dfs(v, x, gcd(val[v], VAL));
  }
  for (i = 0; i < DIV.size(); i++)
    if (cnt[i] <= 1) ans[x] = max(ans[x], DIV[i]);
  for (i = 0; i < DIV.size(); i++)
    if (val[x] % DIV[i] != 0) cnt[i]--;
  ans[x] = max(ans[x], VAL);
}
int main() {
  scanf("%d", &n);
  for (i = 1; i <= n; i++) scanf("%d", &val[i]);
  for (i = 0; i < n - 1; i++) {
    int u, v;
    scanf("%d%d", &u, &v);
    edge[u].push_back(v);
    edge[v].push_back(u);
  }
  for (i = 1; i <= val[1]; i++)
    if (val[1] % i == 0) DIV.push_back(i);
  dfs(1, 0, val[1]);
  for (i = 1; i <= n; i++) printf("%d ", ans[i]);
}
