#include <bits/stdc++.h>
using namespace std;
const int maxn = 2000100;
int a[200100];
int tot;
vector<int> g[maxn];
int val[maxn];
int l[maxn];
const int N = 2000100;
int prime[N];
vector<int> s[N];
void init() {
  for (int i = 1; i < N; i++) prime[i] = i;
  for (int i = 2; i < sqrt(N + 0.5); i++)
    if (prime[i] == i)
      for (int j = i * i; j < N; j += i) prime[j] = i;
}
void getl(int u, int fa) {
  l[u] = ++tot;
  for (int i = 0; i < g[u].size(); i++) {
    int v = g[u][i];
    if (v - fa) getl(v, u);
  }
}
void dfs(int u, int fa) {
  val[u] = -1;
  int maxl = -1;
  int x = a[u];
  while (x > 1) {
    int p = prime[x];
    vector<int> &S = s[p];
    if (!s[p].empty() && l[s[p].back()] > maxl)
      val[u] = s[p].back(), maxl = l[s[p].back()];
    s[p].push_back(u);
    while (x % p == 0) x /= p;
  }
  for (int i = 0; i < g[u].size(); i++) {
    int v = g[u][i];
    if (v == fa) continue;
    dfs(v, u);
  }
  x = a[u];
  while (x > 1) {
    int p = prime[x];
    s[p].pop_back();
    while (x % p == 0) x /= p;
  }
}
int n, Q;
int main() {
  init();
  cin >> n >> Q;
  for (int i = 1; i <= n; i++) cin >> a[i];
  for (int i = 1; i < n; i++) {
    int x, y;
    cin >> x >> y;
    g[x].push_back(y);
    g[y].push_back(x);
  }
  tot = 0;
  getl(1, -1);
  dfs(1, -1);
  while (Q--) {
    int cmd, u, w;
    cin >> cmd >> u;
    if (cmd == 2) {
      cin >> w;
      a[u] = w;
      for (int i = 1; i < N; i++) s[i].clear();
      dfs(1, -1);
    }
    if (cmd == 1) {
      printf("%d\n", val[u]);
    }
  }
}
