#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
long long gcd(long long a, long long b) {
  if (b == 0) return a;
  return gcd(b, a % b);
}
long long expo(long long base, long long pow) {
  long long ans = 1;
  while (pow != 0) {
    if (pow & 1 == 1) {
      ans = ans * base;
      ans = ans % mod;
    }
    base *= base;
    base %= mod;
    pow /= 2;
  }
  return ans;
}
long long inv(long long x) { return expo(x, mod - 2); }
unsigned long long llrand() {
  unsigned long long r = 0;
  for (int i = 0; i < 5; ++i) {
    r = (r << 15) | (rand() & 0x7FFF);
  }
  return r & 0xFFFFFFFFFFFFFFFFULL;
}
int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
const int M = 200022;
int ans[M], arr[M];
vector<int> vec[M];
int val[M];
int cmax = 0;
void dfs(int u, int p, int up, int till) {
  ans[u] = till;
  for (int i = 1; i * i <= arr[u]; i++) {
    if (arr[u] % i == 0) {
      val[i]++;
      if (i * i != arr[u]) val[arr[u] / i]++;
      if (val[i] >= up) {
        ans[u] = max(ans[u], i);
      }
      if (val[arr[u] / i] >= up) {
        ans[u] = max(ans[u], arr[u] / i);
      }
    }
  }
  for (int i = 0; i < vec[u].size(); i++) {
    int v = vec[u][i];
    if (v == p) continue;
    dfs(v, u, up + 1, gcd(till, arr[u]));
  }
  for (int i = 1; i * i <= arr[u]; i++) {
    if (arr[u] % i == 0) {
      val[i]--;
      if (i * i != arr[u]) val[arr[u] / i]--;
    }
  }
}
int main() {
  int n;
  scanf("%d", &(n));
  for (int i = 1; i <= n; i++) {
    scanf("%d", &(arr[i]));
  }
  for (int i = 1; i < n; i++) {
    int u, v;
    scanf("%d", &(u));
    scanf("%d", &(v));
    vec[u].push_back(v);
    vec[v].push_back(u);
  }
  dfs(1, 0, 0, 0);
  for (int i = 1; i <= n; i++) {
    printf("%d ", ans[i]);
  }
}
