#include <bits/stdc++.h>
using namespace std;
int n;
int a[200001];
vector<int> G[200001];
int res[200001];
vector<int> divisor;
vector<int> now;
int gcd(int x, int y) {
  if (y == 0) return x;
  return gcd(y, x % y);
}
void dfs(int v, int p) {
  for (int i = 0; i < G[v].size(); i++) {
    if (p != G[v][i]) {
      res[G[v][i]] = gcd(res[v], a[G[v][i]]);
      dfs(G[v][i], v);
    }
  }
}
void dfs2(int v, int p, int dist) {
  for (int i = 0; i < divisor.size(); i++) {
    now[i] += (a[v] % divisor[i] == 0);
    if (now[i] >= dist) {
      res[v] = max(res[v], divisor[i]);
    }
  }
  for (int i = 0; i < G[v].size(); i++) {
    if (p != G[v][i]) {
      dfs2(G[v][i], v, dist + 1);
    }
  }
  for (int i = 0; i < divisor.size(); i++) {
    now[i] -= (a[v] % divisor[i] == 0);
  }
}
int main(void) {
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    scanf("%d", &a[i]);
  }
  for (int i = 0; i < n - 1; i++) {
    int f, t;
    scanf("%d%d", &f, &t);
    f--;
    t--;
    G[f].push_back(t);
    G[t].push_back(f);
  }
  int tmp = a[0];
  a[0] = 0;
  dfs(0, -1);
  a[0] = tmp;
  for (int i = 1; i * i <= a[0]; i++) {
    if (a[0] % i == 0) {
      divisor.push_back(i);
      divisor.push_back(a[0] / i);
      if (i * i == a[0]) {
        divisor.pop_back();
      }
    }
  }
  sort(divisor.begin(), divisor.end());
  now.resize(divisor.size());
  dfs2(0, -1, 0);
  for (int i = 0; i < n; i++) {
    printf("%d%c", res[i], i + 1 == n ? '\n' : ' ');
  }
  return 0;
}
