#include <bits/stdc++.h>
using namespace std;
int const MAXN = 2e6 + 9;
int const MAXNN = 1e5 + 9;
int p[MAXN], depth[MAXNN], ans[MAXNN], nbr[MAXNN];
map<int, int> id;
stack<pair<int, int>> st[150000];
vector<vector<int>> adj;
void getDepth(int node, int p) {
  for (auto child : adj[node]) {
    if (child == p) continue;
    depth[child] = 1 + depth[node];
    getDepth(child, node);
  }
}
void add(int node) {
  int x = nbr[node];
  while (x > 1) {
    st[id[p[x]]].push(make_pair(node, depth[node]));
    x /= p[x];
  }
}
void del(int node) {
  int x = nbr[node];
  while (x > 1) {
    st[id[p[x]]].pop();
    x /= p[x];
  }
}
void DFS(int node, int par) {
  int x = nbr[node];
  int ret = -1;
  int dep = -1;
  while (x > 1) {
    if (!st[id[p[x]]].empty() && st[id[p[x]]].top().second > dep)
      dep = st[id[p[x]]].top().second, ret = st[id[p[x]]].top().first;
    x /= p[x];
  }
  ans[node] = ret;
  add(node);
  for (auto child : adj[node]) {
    if (child == par) continue;
    DFS(child, node);
  }
  del(node);
}
int main() {
  int cnt = 0;
  for (int i = 0; i < MAXN; i++) p[i] = i;
  for (int i = 2; i < MAXN; i++)
    if (p[i] == i) {
      id[i] = cnt++;
      for (int j = 2 * i; j < MAXN; j += i)
        if (p[j] == j) p[j] = i;
    }
  int n, q;
  cin >> n >> q;
  adj = vector<vector<int>>(n + 1);
  for (int i = 1; i <= n; i++) cin >> nbr[i];
  for (int i = 0; i < n - 1; i++) {
    int u, v;
    cin >> u >> v;
    adj[u].push_back(v);
    adj[v].push_back(u);
  }
  getDepth(1, -1);
  DFS(1, -1);
  while (q--) {
    int u, v, t;
    cin >> t;
    if (t == 1) {
      cin >> v;
      cout << ans[v] << endl;
    } else {
      cin >> v >> u;
      nbr[v] = u;
      DFS(1, -1);
    }
  }
}
