#include <bits/stdc++.h>
using namespace std;
int gcd(int x, int y) {
  if (y == 0)
    return x;
  else
    return gcd(y, x % y);
}
vector<int> ed[200001];
int an[200001];
int b[200001];
set<int> o[2000001];
void dfs(int x, int g, int p) {
  int i;
  if (x == 1) {
    an[x] = b[1];
    o[x].insert(0);
  } else {
    o[x].insert(g);
    an[x] = g;
    if (o[p].size()) {
      set<int>::iterator f = o[p].begin();
      for (i = 0; i < o[p].size(); i++) {
        int y = gcd(b[x], *f);
        an[x] = max(an[x], y);
        if (y != 1) o[x].insert(y);
        f++;
      }
    }
  }
  g = gcd(g, b[x]);
  for (i = 0; i < ed[x].size(); i++) {
    if (ed[x][i] != p) {
      dfs(ed[x][i], g, x);
    }
  }
}
int main() {
  int n;
  cin >> n;
  int i;
  for (i = 1; i <= n; i++) cin >> b[i];
  for (i = 1; i < n; i++) {
    int x, y;
    cin >> x >> y;
    ed[x].push_back(y);
    ed[y].push_back(x);
  }
  dfs(1, 0, 0);
  for (i = 1; i <= n; i++) cout << an[i] << " ";
  cout << endl;
  return 0;
}
