#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 1e3 + 7;
struct node {
  int ne, to;
} e1[N * 2 + 1];
int gcd(int a, int b) { return b == 0 ? a : gcd(b, a % b); }
int n, a[N], head[N], cont, dp[N], g[N], last[N], ans[N], gf[N];
void in(int x, int y) {
  ++cont;
  e1[cont].to = y;
  e1[cont].ne = head[x];
  head[x] = cont;
}
int calc(int x) {
  int ret = dp[x];
  int cc = 0;
  for (int i = 1; i <= 21; ++i) {
    if (!x) break;
    ret = max(ret, gcd(dp[gf[x]], cc));
    cc = gcd(cc, a[x]);
    x = gf[x];
  }
  return ret;
}
void dfs(int i, int fa) {
  dp[i] = gcd(dp[fa], a[i]), gf[i] = fa;
  ans[i] = calc(i);
  for (int tmp = head[i]; tmp; tmp = e1[tmp].ne) {
    int y = e1[tmp].to;
    if (y != fa) dfs(y, i);
  }
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; ++i) scanf("%d", &a[i]);
  for (int i = 1; i < n; ++i) {
    int x, y;
    scanf("%d%d", &x, &y);
    in(x, y);
    in(y, x);
  }
  dp[1] = a[1];
  dfs(1, 0);
  for (int i = 1; i <= n; ++i) printf("%d ", ans[i]);
}
