3 2
1 0 1
1 2
2 3
 10 10
-1 -1 -1 -1 -1 -1 -1 -1 -1 -1
6 7
8 3
6 4
4 2
9 2
5 10
9 8
10 7
5 1
6 2

2
1
2
 0

#include <bits/stdc++.h>
using namespace std;
vector<int> g[100100];
int arr[100100], dp[100100];
int mdc(int a, int b) {
  if (a == 0) return b;
  return mdc(b % a, a);
}
void f(int u, int MDC) {
  for (int i = 0; i < (int)g[u].size(); i++) {
    int v = g[u][i];
    if (dp[v] == -1) {
      if (u == 1)
        dp[v] = max(dp[u], arr[v]);
      else
        dp[v] = max(mdc(dp[u], arr[v]), MDC);
      f(v, mdc(MDC, arr[v]));
    }
  }
}
int main() {
  int n;
  cin >> n;
  for (int i = 1; i <= n; i++) cin >> arr[i];
  for (int i = 1; i < n; i++) {
    int a, b;
    cin >> a >> b;
    g[a].push_back(b);
    g[b].push_back(a);
  }
  memset(dp, -1, sizeof dp);
  dp[1] = arr[1];
  f(1, arr[1]);
  for (int i = 1; i < n; i++) printf("%d ", dp[i]);
  printf("%d\n", dp[n]);
  return 0;
}
