#include <bits/stdc++.h>
using namespace std;
int gcd(int x, int y) {
  if (y == 0) return x;
  return gcd(y, x % y);
}
int lcm(int x, int y) { return x / gcd(x, y) * y; }
int lowbit(int x) { return x & (-x); }
int quickmod(int x, int y, int mod) {
  int ans = 1;
  while (y) {
    if (y & 1) ans = ans * 1LL * x % mod;
    y >>= 1;
    x = x * 1LL * x % mod;
  }
  return ans;
}
const int INF = 0x3f3f3f3f;
const double EPS = 1e-7;
const double PI = acos(-1.0);
const int MOD = 23333333;
int n;
int num[200005];
int cnt[200005];
int ans[200005];
vector<int> edge[200005];
void dfs(int x, int fa, int d, int g) {
  ans[x] = g;
  for (int i = 1; i * i <= num[x]; i++) {
    if (num[x] % i == 0) {
      if (i * i == num[x]) {
        cnt[i]++;
        if (cnt[i] >= d) ans[x] = max(ans[x], i);
      } else {
        cnt[i]++;
        if (cnt[i] >= d) ans[x] = max(ans[x], i);
        cnt[num[x] / i]++;
        if (cnt[num[x] / i] >= d) ans[x] = max(ans[x], num[x] / i);
      }
    }
  }
  for (int i = 0; i < edge[x].size(); i++) {
    int v = edge[x][i];
    if (v == fa) continue;
    dfs(v, x, d + 1, gcd(g, num[x]));
  }
  for (int i = 1; i * i <= num[x]; i++) {
    if (num[x] % i == 0) {
      if (i * i == num[x])
        cnt[i]--;
      else {
        cnt[i]--;
        cnt[num[x] / i]--;
      }
    }
  }
}
int main() {
  while (scanf("%d", &n) != EOF) {
    memset(cnt, 0, sizeof(cnt));
    for (int i = 1; i <= n; i++) {
      edge[i].clear();
      scanf("%d", &num[i]);
    }
    for (int i = 1; i <= n - 1; i++) {
      int temp1, temp2;
      scanf("%d%d", &temp1, &temp2);
      edge[temp1].push_back(temp2);
      edge[temp2].push_back(temp1);
    }
    dfs(1, 0, 0, 0);
    for (int i = 1; i <= n; i++) printf("%d%c", ans[i], i == n ? '\n' : ' ');
  }
  return 0;
}
