#include <bits/stdc++.h>
using namespace std;
int Set(int n, int pos) { return n = n | (1 << pos); }
int reset(int n, int pos) { return n = n & ~(1 << pos); }
bool check(int n, int pos) { return (bool)(n & (1 << pos)); }
long long gcd(long long a, long long b) {
  if (b == 0)
    return a;
  else
    return gcd(b, a % b);
};
long long lcm(long long a, long long b) { return (a * b) / gcd(a, b); };
vector<int> edges[200005];
bool visited[200005];
int val[200005];
set<int> st[200005];
set<int>::iterator it;
void dfs(int u, int par, int G) {
  visited[u] = 1;
  for (it = st[par].begin(); it != st[par].end(); it++)
    st[u].insert(gcd(*it, val[u]));
  st[u].insert(G);
  G = gcd(G, val[u]);
  st[u].insert(G);
  int len = edges[u].size();
  for (int i = 0; i < len; i++) {
    int v = edges[u][i];
    if (!visited[v]) dfs(v, u, G);
  }
}
int main() {
  int n, x, y;
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &val[i]);
  }
  for (int i = 1; i < n; i++) {
    scanf("%d%d", &x, &y);
    edges[x].push_back(y);
    edges[y].push_back(x);
  }
  dfs(1, 0, 0);
  for (int i = 1; i <= n; i++) printf("%d ", *st[i].rbegin());
  printf("\n");
  return 0;
}
