#include <bits/stdc++.h>
using namespace std;
vector<int> line[200005];
int b[200005], a[200005], check[200005], cnt[200005], n;
int gcd(int x, int y) {
  if (y == 0)
    return x;
  else
    return gcd(y, x % y);
}
void dfs(int st, int fa, int deep) {
  int flag;
  b[st] = gcd(a[st], b[fa]);
  check[st] = b[fa];
  for (int i = 1; i * i <= a[st]; i++) {
    if (a[st] % i == 0) {
      flag = i;
      if (cnt[flag] >= deep - 2) check[st] = max(flag, check[st]);
      flag = a[st] / i;
      if (cnt[flag] >= deep - 2) check[st] = max(flag, check[st]);
      if (i * i == a[st])
        cnt[i]++;
      else
        cnt[i]++, cnt[a[st] / i]++;
    }
  }
  for (int i = 0; i < line[st].size(); i++) {
    int k = line[st][i];
    if (k == fa) continue;
    dfs(k, st, deep + 1);
  }
  for (int i = 1; i * i <= a[st]; i++) {
    if (a[st] % i == 0) {
      if (i * i == a[st])
        cnt[i]--;
      else
        cnt[i]--, cnt[a[st] / i]--;
    }
  }
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) cin >> a[i];
  for (int i = 1; i < n; i++) {
    int x, y;
    scanf("%d %d", &x, &y);
    line[x].push_back(y);
    line[y].push_back(x);
  }
  dfs(1, 0, 1);
  for (int i = 1; i <= n; i++) cout << check[i] << " ";
}
