#include <bits/stdc++.h>
using namespace std;
const int maxn = 100005;
int n, q, w[maxn], f[maxn];
vector<int> a[maxn];
void enter() {
  cin >> n >> q;
  for (int i = 1; i <= n; i++) cin >> w[i];
  for (int i = 1; i <= n - 1; i++) {
    int x, y;
    cin >> x >> y;
    a[x].push_back(y);
    a[y].push_back(x);
  }
  f[1] = -1;
}
int gcd(int a, int b) {
  if (b == 0) return a;
  return gcd(b, a % b);
}
void dfs(int u) {
  int v;
  for (int i = 0; i < a[u].size(); i++) {
    v = a[u][i];
    if (!f[v]) {
      f[v] = u;
      dfs(v);
    }
  }
}
int find_res(int v) {
  int u = f[v];
  while (u != -1) {
    if (gcd(w[u], w[v]) > 1) return u;
    u = f[u];
  }
  return -1;
}
void process() {
  int t;
  dfs(1);
  while (q--) {
    cin >> t;
    if (t == 1) {
      int v;
      cin >> v;
      cout << find_res(v) << endl;
    } else {
      int x, y;
      cin >> x >> y;
      w[x] = y;
    }
  }
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  enter();
  process();
}
