#include <bits/stdc++.h>
using namespace std;
struct Node {
  bool visited;
  int val;
  int ans;
  vector<size_t> children;
};
struct RootValueDivisor {
  int val;
  size_t times;
  inline bool operator<(const RootValueDivisor& rhs) const {
    return val < rhs.val;
  }
};
vector<Node> g;
vector<RootValueDivisor> divisors;
inline void findDivisors(int rootValue) {
  for (int i = 1; i * i <= rootValue; ++i) {
    divisors.push_back({i, 0});
    if (i * i != rootValue) divisors.push_back({rootValue / i, 0});
  }
  sort(divisors.begin(), divisors.end());
}
int gcd(int a, int b) { return b == 0 ? a : gcd(b, a % b); }
void dfsGcd(size_t v, int ans) {
  Node& n = g[v];
  n.visited = true;
  ans = gcd(n.val, ans);
  n.ans = ans;
  for (size_t to : n.children)
    if (!g[to].visited) dfsGcd(to, ans);
}
void dfsDivisors(size_t v, size_t depth) {
  Node& n = g[v];
  n.visited = true;
  int ans = 0;
  for (auto& divisor : divisors) {
    if (n.val % divisor.val == 0) {
      ++divisor.times;
    }
    if (divisor.times >= depth) {
      ans = divisor.val;
    }
  }
  n.ans = max(n.ans, ans);
  for (size_t to : n.children)
    if (!g[to].visited) dfsDivisors(to, depth + 1);
  for (auto& divisor : divisors)
    if (n.val % divisor.val == 0) --divisor.times;
}
int main() {
  ios_base::sync_with_stdio(false);
  size_t n;
  cin >> n;
  g.resize(n);
  for (size_t i = 0; i < n; ++i) {
    g[i].visited = false;
    cin >> g[i].val;
  }
  for (size_t i = 0; i < n - 1; ++i) {
    size_t x, y;
    cin >> x >> y;
    --x;
    --y;
    g[x].children.push_back(y);
    g[y].children.push_back(x);
  }
  {
    const auto rootAns = g[0].val;
    g[0].val = 0;
    dfsGcd(0, 0);
    g[0].val = rootAns;
    g[0].ans = rootAns;
    for (auto& n : g) n.visited = false;
  }
  findDivisors(g[0].val);
  dfsDivisors(0, 0);
  for (auto& n : g) cout << n.ans << ' ';
  cout << endl;
  return 0;
}
