#include <bits/stdc++.h>
using namespace std;
const int MAXN = 2e5 + 555;
int sz, N;
int Fi[MAXN];
struct Edge {
  int v, nx;
} e[MAXN << 2];
void E_init() {
  sz = 0;
  memset(Fi, -1, sizeof(Fi));
}
void E_add(int u, int v) {
  e[sz].v = v, e[sz].nx = Fi[u];
  Fi[u] = sz++;
}
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
int nd[MAXN], path[MAXN];
vector<int> rec[MAXN];
void init() {
  E_init();
  scanf("%d", &N);
  for (int i = 1; i < (N + 1); ++i) scanf("%d", &nd[i]);
  for (int i = 1; i < (N); ++i) {
    int u, v;
    scanf("%d %d", &u, &v);
    E_add(u, v);
    E_add(v, u);
  }
};
void dfs(int u, int fa) {
  if (fa == -1) {
    rec[u].push_back(0);
    rec[u].push_back(nd[u]);
    path[u] = nd[u];
  } else {
    rec[u].push_back(path[fa]);
    path[u] = gcd(path[fa], nd[u]);
    for (int i = 0; i < (rec[fa].size()); ++i)
      rec[u].push_back(gcd(rec[fa][i], nd[u]));
    sort(rec[u].begin(), rec[u].end());
    rec[u].erase(unique(rec[u].begin(), rec[u].end()), rec[u].end());
  }
  for (int i = Fi[u]; i != -1; i = e[i].nx) {
    int v = e[i].v;
    if (v != fa) dfs(v, u);
  }
}
int main() {
  init();
  dfs(1, -1);
  for (int i = 1; i < (N + 1); ++i)
    printf("%d%c", rec[i].back(), i == N ? '\n' : ' ');
}
