#include <bits/stdc++.h>
using namespace std;
int n, a[200001], i, j, x, y, b1[200001], b2[200001], res = 0, v[200001], aux;
vector<int> G[200001];
int comp[200001], freq[200001], nr = 0;
int cmmdc(int a, int b) {
  int r;
  if (b == 0) return a;
  if (a == 0) return b;
  r = a % b;
  while (r != 0) {
    a = b;
    b = r;
    r = a % b;
  }
  return b;
}
void DFS1(int k, int res) {
  v[k] = 1;
  int aux = res;
  res = cmmdc(res, a[k]);
  b1[k] = res;
  int i;
  for (i = 0; i < G[k].size(); i++)
    if (v[G[k][i]] == 0) DFS1(G[k][i], res);
  res = aux;
}
void DFS2(int k, int depth) {
  int i;
  v[k] = 1;
  b2[k] = -1;
  for (i = 1; i <= nr; i++)
    if (a[k] % comp[i] == 0) freq[i]++;
  for (i = 1; i <= nr; i++)
    if (freq[i] >= (depth - 1))
      if (b2[k] < comp[i]) b2[k] = comp[i];
  for (i = 0; i < G[k].size(); i++)
    if (v[G[k][i]] == 0) {
      DFS2(G[k][i], depth + 1);
    }
  for (i = 1; i <= nr; i++)
    if (a[k] % comp[i] == 0) freq[i]--;
}
int main() {
  scanf("%d", &n);
  for (i = 1; i <= n; i++) scanf("%d", &a[i]);
  for (i = 1; i <= n - 1; i++) {
    scanf("%d%d", &x, &y);
    G[x].push_back(y);
    G[y].push_back(x);
  }
  aux = a[1];
  a[1] = 0;
  DFS1(1, 0);
  a[1] = aux;
  memset(v, 0, sizeof(v));
  for (i = 1; i * i <= a[1]; i++)
    if (a[1] % i == 0) {
      nr++;
      comp[nr] = i;
      if (i != a[1] / i) {
        nr++;
        comp[nr] = a[1] / i;
      }
    }
  DFS2(1, 1);
  for (i = 1; i <= n; i++)
    if (b1[i] > b2[i])
      printf("%d ", b1[i]);
    else
      printf("%d ", b2[i]);
  return 0;
}
