#include <bits/stdc++.h>
using namespace std;
int n, m, k;
int a[100500];
vector<int> p;
int f[2000500];
vector<int> g[100500];
vector<int> st[2000500];
int tin[100500];
int ans[100500];
int timer;
inline void build(int v, int p = -1) {
  int x = a[v];
  while (x > 1) {
    if (st[f[x]].size() > 0 &&
        (ans[v] == -1 || tin[st[f[x]].back()] > tin[ans[v]])) {
      ans[v] = st[f[x]].back();
    }
    x /= f[x];
  }
  x = a[v];
  while (x > 1) {
    st[f[x]].push_back(v);
    x /= f[x];
  }
  for (int i = 0; i < g[v].size(); ++i) {
    if (g[v][i] == p) continue;
    build(g[v][i], v);
  }
  x = a[v];
  while (x > 1) {
    st[f[x]].pop_back();
    x /= f[x];
  }
}
inline void dfs(int v, int p = -1) {
  tin[v] = timer++;
  for (int i = 0; i < g[v].size(); ++i)
    if (g[v][i] != p) dfs(g[v][i], v);
}
int main() {
  cin >> n >> m;
  for (int i = 0; i < n; ++i) cin >> a[i];
  for (int i = 2; i <= 2000000; ++i) {
    if (f[i] == 0) {
      f[i] = i;
      p.push_back(i);
    }
    for (int j = 0; j < p.size() && p[j] <= f[i] && p[j] * i <= 2000000; ++j) {
      f[p[j] * i] = p[j];
    }
  }
  int x, y;
  for (int i = 0; i < n - 1; ++i) {
    cin >> x >> y;
    x--;
    y--;
    g[x].push_back(y);
    g[y].push_back(x);
  }
  for (int i = 0; i < n; ++i) ans[i] = -1;
  dfs(0);
  build(0);
  int c;
  for (int i = 0; i < m; ++i) {
    cin >> c;
    if (c == 1) {
      cin >> x;
      x--;
      if (ans[x] == -1)
        cout << -1 << endl;
      else
        cout << ans[x] + 1 << endl;
    } else {
      cin >> x >> y;
      x--;
      a[x] = y;
      for (int i = 0; i < n; ++i) ans[i] = -1;
      build(0);
    }
  }
  return 0;
}
