#include <bits/stdc++.h>
using namespace std;
const int N = 200005;
const int inf = 1000 * 1000 * 1000;
const int mod = 1000 * 1000 * 1000 + 7;
int n, c[N], h[N];
vector<int> g[N];
int parent[N];
int dp[N][22];
int D[N][22];
int gcd(int a, int b) {
  if (b == 0) return a;
  return gcd(b, a % b);
}
void dfs(int v, int r) {
  h[v] = r;
  dp[v][0] = parent[v];
  for (int i = 1; i <= 20; i++) dp[v][i] = dp[dp[v][i - 1]][i - 1];
  D[v][0] = c[v];
  for (int i = 1; i <= 20; i++)
    D[v][i] = gcd(D[dp[v][i - 1]][i - 1], D[v][i - 1]);
  for (int i = 0; i < (int)g[v].size(); i++) {
    int to = g[v][i];
    if (to == parent[v]) continue;
    parent[to] = v;
    dfs(to, r + 1);
  }
}
int calc(int v, int p) {
  int answ = 0;
  for (int i = 20; i >= 0; i--) {
    if ((p >> i) & 1) {
      answ = gcd(answ, D[v][i]);
      v = dp[v][i];
    }
  }
  return answ;
}
int lift(int v, int p) {
  for (int i = 20; i >= 0; i--) {
    if ((p >> i) & 1) {
      v = dp[v][i];
    }
  }
  return v;
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) scanf("%d", &c[i]);
  for (int i = 1; i < n; i++) {
    int a, b;
    scanf("%d%d", &a, &b);
    g[a].push_back(b);
    g[b].push_back(a);
  }
  parent[1] = 1;
  dfs(1, 1);
  for (int i = 1; i <= n; i++) {
    int ind = 1, v = i, G = c[i];
    int pat = D[parent[v]][20];
    while (true) {
      int ina = 1, inb = h[i] - ind, len = 0;
      while (ina <= inb) {
        int mid = (ina + inb) / 2;
        int P = calc(v, mid + 1);
        if (P % G == 0) {
          len = mid;
          ina = mid + 1;
        } else
          inb = mid - 1;
      }
      v = lift(v, len);
      if (v == 1) {
        pat = max(pat, G);
        break;
      }
      v = parent[v];
      int x = 0;
      if (v != 1) x = D[parent[v]][20];
      pat = max(pat, gcd(G, x));
      ind += len + 1;
      G = gcd(G, c[v]);
    }
    printf("%d ", pat);
  }
  cout << endl;
  return 0;
}
