#include <bits/stdc++.h>
using namespace std;
int a[200004];
int m[200004];
vector<int> adj[200004];
int dp[200004];
vector<int> v[200004];
void dfs(int x, int dis, int par) {
  int i;
  int ans = 0;
  for (i = 0; i < v[a[x]].size(); i++) {
    m[v[(a[x])][i]]++;
    if (m[v[(a[x])][i]] >= dis - 1) ans = max(ans, v[a[x]][i]);
  }
  for (int it : v[a[par]]) {
    if (m[it] == dis - 1) {
      ans = max(ans, it);
    }
  }
  dp[x] = ans;
  for (int it : adj[x]) {
    if (it != par) {
      dfs(it, dis + 1, x);
    }
  }
  for (i = 0; i < v[a[x]].size(); i++) {
    m[v[(a[x])][i]]--;
  }
}
void pre() {
  int i, j;
  int k = 0;
  for (i = 1; i <= 200000; i++) {
    for (j = i; j <= 200000; j += i) {
      v[j].push_back(i);
    }
  }
}
int main() {
  pre();
  int n, i, j, k, l, x, y;
  scanf("%d", &n);
  for (i = 1; i <= n; i++) {
    scanf("%d", &a[i]);
  }
  for (i = 1; i <= n - 1; i++) {
    scanf("%d %d", &x, &y);
    adj[x].push_back(y);
    adj[y].push_back(x);
  }
  dfs(1, 1, 0);
  for (i = 1; i <= n; i++) printf("%d ", dp[i]);
  return 0;
}
