#include <bits/stdc++.h>
using namespace std;
struct Node {
  int value;
  int father = -1;
  int beauty = 0;
  int total = 0;
  vector<int> edges;
};
using Tree = vector<Node>;
const int kLog = 20;
int Gcd(int a, int b) {
  if (b == 0) {
    return a;
  } else if (a == 0) {
    return b;
  }
  return Gcd(b, a % b);
}
void Dfs(Tree &t, int node) {
  int father = t[node].father;
  if (father >= 0) {
    t[node].beauty = t[father].total;
    t[node].total = Gcd(t[father].total, t[node].value);
  }
  int gcd = t[node].value;
  for (int i = 0; i < kLog && father >= 0; ++i) {
    int beauty = gcd;
    if (t[father].father >= 0) {
      int fa = t[father].father;
      beauty = Gcd(gcd, t[fa].total);
    }
    t[node].beauty = max(t[node].beauty, beauty);
    gcd = Gcd(gcd, t[father].value);
    father = t[father].father;
  }
  for (const auto &son : t[node].edges) {
    if (son == t[node].father) {
      continue;
    }
    t[son].father = node;
    Dfs(t, son);
  }
}
int main() {
  int nodes;
  cin >> nodes;
  Tree tree(nodes);
  for (int i = 0; i < nodes; ++i) {
    cin >> tree[i].value;
  }
  for (int i = 1; i < nodes; ++i) {
    int x, y;
    cin >> x >> y;
    tree[x - 1].edges.push_back(y - 1);
    tree[y - 1].edges.push_back(x - 1);
  }
  tree[0].beauty = tree[0].value;
  tree[0].total = tree[0].value;
  Dfs(tree, 0);
  for (const auto &node : tree) {
    cout << node.beauty << " ";
  }
  return 0;
}
