#include <bits/stdc++.h>
using namespace std;
inline int read() {
  int x = 0, f = 1;
  char ch = getchar();
  while (!isdigit(ch)) {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (isdigit(ch)) {
    x = x * 10 + ch - 48;
    ch = getchar();
  }
  return x * f;
}
int n = read();
int weight[200001], dp[200001];
vector<int> a[200001];
map<int, bool> used[200001][2];
int gcd(int x, int y) {
  if (x < y) swap(x, y);
  if (!y) return x;
  return gcd(y, x % y);
}
void dfs(int where, int dad, bool reset, int the_weight) {
  if (used[where][reset][the_weight]) return;
  used[where][reset][the_weight] = true;
  int kk = gcd(weight[where], the_weight);
  dp[where] = max(kk, dp[where]);
  if (!reset) dp[where] = max(dp[where], the_weight);
  for (int i = 0; i < a[where].size(); i++) {
    if (dad == a[where][i]) continue;
    dfs(a[where][i], where, reset, kk);
    if (!reset) dfs(a[where][i], where, true, the_weight);
  }
  return;
}
int main() {
  for (int i = 1; i <= n; i++) weight[i] = read();
  for (int i = 1; i < n; i++) {
    int x = read(), y = read();
    a[x].push_back(y);
    a[y].push_back(x);
  }
  dfs(1, 0, false, 0);
  for (int i = 1; i <= n; i++) printf("%d ", dp[i]);
  return 0;
}
