#include <bits/stdc++.h>
using namespace std;
const int maxn = 100000 + 10;
int n, q;
int a[maxn], ans[maxn];
vector<int> e[maxn];
int fa[maxn], dep[maxn];
int pp[2000000 + 10];
void dfs(int u, int f) {
  fa[u] = f;
  dep[u] = dep[f] + 1;
  int b = a[u];
  vector<pair<int, int> > r;
  for (int i = 2; i * i <= b; i++)
    if (b % i == 0) {
      r.push_back(make_pair(i, pp[i]));
      if (ans[u] == -1)
        ans[u] = pp[i];
      else if (dep[pp[i]] > dep[ans[u]])
        ans[u] = pp[i];
      pp[i] = u;
      while (b % i == 0) b /= i;
    }
  if (b > 1) {
    r.push_back(make_pair(b, pp[b]));
    if (ans[u] == -1)
      ans[u] = pp[b];
    else if (dep[pp[b]] > dep[ans[u]])
      ans[u] = pp[b];
    pp[b] = u;
  }
  for (int i = 0; i < e[u].size(); i++) {
    int v = e[u][i];
    if (v == f) continue;
    dfs(v, u);
  }
  for (int i = 0; i < r.size(); i++) {
    pp[r[i].first] = r[i].second;
  }
}
int main() {
  memset(ans, -1, sizeof(ans));
  memset(pp, -1, sizeof(pp));
  cin >> n >> q;
  for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
  for (int i = 1; i < n; i++) {
    int x, y;
    scanf("%d%d", &x, &y);
    e[x].push_back(y);
    e[y].push_back(x);
  }
  dep[0] = 0;
  dfs(1, 0);
  while (q--) {
    int t, v, w;
    scanf("%d%d", &t, &v);
    if (t == 1) {
      printf("%d\n", ans[v]);
    } else {
      scanf("%d", &w);
      a[v] = w;
      memset(ans, -1, sizeof(ans));
      memset(pp, -1, sizeof(pp));
      dfs(1, 0);
    }
  }
}
