#include <bits/stdc++.h>
using namespace std;
int a[1000000 * 2][2], g[1000000], v[1000000], d[20], f[1000000], e[20];
int n;
void ins(int x, int y) {
  static int sum = 1;
  a[++sum][0] = y, a[sum][1] = g[x], g[x] = sum;
}
int gcd(int x, int y) { return !y ? x : gcd(y, x % y); }
void dfs(int x, int Gcd, int fa) {
  int dd[20], ee[20];
  for (int i = 0; i < 20; i++) dd[i] = d[i], ee[i] = e[i];
  for (int i = g[x]; i; i = a[i][1])
    if (a[i][0] != fa) {
      int Gcd1 = gcd(Gcd, v[a[i][0]]);
      for (int j = 1; j <= d[0]; j++)
        d[j] = gcd(v[a[i][0]] / Gcd1, d[j]), e[j] = gcd(e[j], v[a[i][0]]);
      if (Gcd1 != Gcd) d[++d[0]] = Gcd / Gcd1, e[d[0]] = Gcd;
      if (x == 1) d[++d[0]] = v[a[i][0]] / Gcd1, e[d[0]] = v[a[i][0]];
      int tot = 0;
      for (int j = 1; j <= d[0]; j++)
        if (d[j] != 1) d[++tot] = d[j], e[tot] = e[j];
      d[0] = tot;
      f[a[i][0]] = Gcd1;
      for (int j = 1; j <= d[0]; j++) f[a[i][0]] = max(f[a[i][0]], Gcd1 * d[j]);
      dfs(a[i][0], Gcd1, x);
      for (int j = 0; j < 20; j++) d[j] = dd[j], e[j] = ee[j];
    }
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) scanf("%d", &v[i]);
  for (int i = 1; i < n; i++) {
    int x, y;
    scanf("%d %d", &x, &y);
    ins(x, y), ins(y, x);
  }
  f[1] = v[1];
  dfs(1, v[1], 0);
  for (int i = 1; i <= n; i++) {
    printf("%d", f[i]);
    if (i != n) printf(" ");
  }
  return 0;
}
