#include <bits/stdc++.h>
using namespace std;
const int N = 2000005;
int lp[N + 1];
vector<int> pr, adj[100005];
vector<int> v[N];
int a[N], ans[100005], depth[100005];
void seive() {
  for (int i = 2; i <= N; ++i) {
    if (lp[i] == 0) {
      lp[i] = i;
      pr.push_back(i);
    }
    for (int j = 0; j < (int)pr.size() && pr[j] <= lp[i] && i * pr[j] <= N; ++j)
      lp[i * pr[j]] = pr[j];
  }
}
void dfs(int s, int p) {
  int x = a[s];
  while (x > 1) {
    int te = lp[x];
    while (x % te == 0) x /= te;
    int sz = v[te].size();
    if (sz > 0) {
      ;
      if (ans[s] == -1 || depth[ans[s]] < depth[v[te][sz - 1]])
        ans[s] = v[te][sz - 1];
    }
    v[te].push_back(s);
  }
  for (auto it : adj[s]) {
    if (it != p) {
      depth[it] = depth[s] + 1;
      dfs(it, s);
    }
  }
  x = a[s];
  while (x > 1) {
    int te = lp[x];
    while (x % te == 0) x /= te;
    v[te].pop_back();
  }
}
int main() {
  int n, q, i;
  seive();
  scanf("%d%d", &n, &q);
  memset(ans, -1, sizeof(ans));
  for (i = 0; i < n; i++) scanf("%d", &a[i]);
  for (i = 0; i < n - 1; i++) {
    int a, b;
    scanf("%d%d", &a, &b);
    adj[a - 1].push_back(b - 1);
    adj[b - 1].push_back(a - 1);
  }
  dfs(0, -1);
  while (q--) {
    int type, v;
    scanf("%d%d", &type, &v);
    if (type == 1) {
      if (ans[v - 1] == -1) ans[v - 1] = -2;
      printf("%d\n", ans[v - 1] + 1);
    } else {
      int w;
      scanf("%d", &w);
      a[v - 1] = w;
      memset(ans, -1, sizeof(ans));
      dfs(0, -1);
    }
  }
  return 0;
}
