#include <bits/stdc++.h>
using namespace std;
using ll = long long int;
const int sz = 1e5 + 10;
const int pr_sz = 2e6 + 10;
bitset<pr_sz> fl;
vector<int> primes, factors[pr_sz], G[sz];
int ans[sz];
int lvl[sz];
int ar[sz];
void sieve() {
  for (int i = 4; i < pr_sz; i += 2) fl[i] = 1;
  for (int i = 3; i * i < pr_sz; i += 2) {
    if (fl[i]) continue;
    for (int j = i * i; j < pr_sz; j += i) {
      fl[j] = 1;
    }
  }
  primes.push_back(2);
  for (int j = 3; j < pr_sz; j += 2)
    if (!fl[j]) primes.push_back(j);
}
void factorise(int u) {
  int h = ar[u];
  for (int i = 0; i < primes.size() && primes[i] * primes[i] <= h; i++) {
    if (h % primes[i] == 0) {
      if (factors[primes[i]].empty() == false) {
        if (ans[u] == -1) {
          ans[u] = factors[primes[i]].back();
        } else if (lvl[ans[u]] < lvl[factors[primes[i]].back()]) {
          ans[u] = factors[primes[i]].back();
        }
      }
      while (h % primes[i] == 0) {
        h /= primes[i];
      }
      factors[primes[i]].push_back(u);
    }
  }
  if (h != 1) {
    if (factors[h].empty() == false) {
      if (ans[u] == -1) {
        ans[u] = factors[h].back();
      } else if (lvl[ans[u]] < lvl[factors[h].back()]) {
        ans[u] = factors[h].back();
      }
    }
    factors[h].push_back(u);
  }
}
void defactorise(int u) {
  int h = ar[u];
  for (int i = 0; i < primes.size() && primes[i] * primes[i] <= h; i++) {
    if (h % primes[i] == 0) {
      while (h % primes[i] == 0) {
        h /= primes[i];
      }
      factors[primes[i]].pop_back();
    }
  }
  if (h != 1) {
    factors[h].pop_back();
  }
}
void dfs(int u, int p = -1, int dep = 0) {
  lvl[u] = dep;
  factorise(u);
  for (int v : G[u]) {
    if (v != p) dfs(v, u, dep + 1);
  }
  defactorise(u);
}
int main() {
  sieve();
  int n, m;
  while (cin >> n >> m) {
    for (int i = 1; i <= n; i++) cin >> ar[i], G[i].clear();
    for (int i = 1, x, y; i < n; i++) {
      cin >> x >> y;
      G[x].push_back(y);
      G[y].push_back(x);
    }
    memset(ans, -1, sizeof ans);
    dfs(1);
    for (int i = 0, ty, x, y; i < m; i++) {
      cin >> ty >> x;
      if (ty == 1) {
        cout << ans[x] << "\n";
      } else {
        cin >> y;
        ar[x] = y;
        memset(ans, -1, sizeof ans);
        dfs(1);
      }
    }
  }
  return 0;
}
