#include <bits/stdc++.h>   using namespace std;   vector<int> spl;   int p[2000006];   void prime() {     p[0] = p[1] = 0;     for (int i = 2; i < 1420; i++) {       if (!p[i]) {         spl.push_back(i);         for (int j = i * i; j < 2000006; j += i) p[j] = i;       }     }   }   int n, q;   int a[100005];   vector<int> edge[100005];   int par[100005];   int siz[100005];   int dep[100005];   int dfs1(int u, int p, int d) {     par[u] = p;     siz[u] = 1;     dep[u] = d;     for (auto v : edge[u])       if (v != p) siz[u] += dfs1(v, u, d + 1);     return siz[u];   }   int cnt;   int reid[100005];   int reidm1[100005];   int head[100005];   void dfs2(int u, int h) {     reid[u] = cnt;     reidm1[cnt++] = u;     head[reid[u]] = reid[h];     int ch = 0, s = 0;     for (auto v : edge[u])       if (v != par[u] && s < siz[v]) s = siz[v], ch = v;     if (!ch) return;     dfs2(ch, h);     for (auto v : edge[u])       if (v != par[u] && v != ch) dfs2(v, v);   }   vector<int> prv[2000006];   void scan() {     for (int id = 1; id <= n; id++) {       int val = a[reidm1[id]];       while (p[val] > 0) {         prv[p[val]].push_back(id);         int k = p[val];         while (val % k == 0) val /= k;       }       if (val > 1) prv[val].push_back(id);     }   }   void build(int md) {     if (md) dfs1(1, 0, 1);     if (md) {       cnt = 1;       dfs2(1, 1);     }     scan();   }   int find(int id, int p) {     if (id < 1) return -1;     auto it = upper_bound(prv[p].begin(), prv[p].end(), id);     it--;     if (head[id] <= *it && *it <= id)       return *it;     else       return find(reid[par[reidm1[head[id]]]], p);   }   void sol() {     while (q--) {       int op, x, y;       scanf( %d , &op);       if (op == 1) {         scanf( %d , &x);         int val = a[x], ans = -1;         while (p[val]) {           ans = max(ans, find(reid[par[x]], p[val]));           int k = p[val];           while (val % k == 0) val /= k;         }         if (val > 1) ans = max(ans, find(reid[par[x]], val));         printf( %d n , ans == -1 ? -1 : reidm1[ans]);       } else {         scanf( %d%d , &x, &y);         int id = reid[x];         int val = a[x];         while (p[val] > 0) {           int idx = lower_bound(prv[p[val]].begin(), prv[p[val]].end(), id) -                     prv[p[val]].begin();           prv[p[val]].erase(prv[p[val]].begin() + idx);           int k = p[val];           while (val % k == 0) val /= k;         }         if (val > 1) {           int idx = lower_bound(prv[val].begin(), prv[val].end(), id) -                     prv[val].begin();           prv[val].erase(prv[val].begin() + idx);         }         val = a[x] = y;         while (p[val] > 0) {           prv[p[val]].push_back(id);           sort(prv[p[val]].begin(), prv[p[val]].end());           int k = p[val];           while (val % k == 0) val /= k;         }         if (val > 1) {           prv[val].push_back(id);           sort(prv[val].begin(), prv[val].end());         }       }     }   }   int main() {     prime();     scanf( %d%d , &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);       edge[x].push_back(y);       edge[y].push_back(x);     }     build(1);     sol();     return 0;   }