#include <bits/stdc++.h>   using namespace std;   const int N = 1000010, P = 2000010;   int f[P];   int n, t, a[N];   int d[N], g[N], r[P];   vector<int> q[P], v[N];   void init(int c, int p) {     vector<int> z;     int cv = a[c];     d[c] = d[p] + 1;     g[c] = -1;     if (c == 1) fill(r + 1, r + P, -1);     for (int i = 0; i < q[cv].size(); i++) {       int t = q[cv][i];       if (g[c] == -1 || d[r[t]] > d[g[c]]) g[c] = r[t];       z.push_back(r[t]);       r[t] = c;     }     for (int i = 0; i < v[c].size(); i++)       if (v[c][i] != p) init(v[c][i], c);     for (int i = 0; i < q[cv].size(); i++) r[q[cv][i]] = z[i];   }   int main() {     scanf( %d %d , &n, &t);     for (int i = 2; i < P; i++)       if (!f[i])         for (int j = 1; i * j < P; j++) f[i * j] = i;     for (int i = 2; i < P; i++) {       int c = i / f[i];       if (f[c] != f[i]) q[i].push_back(f[i]);       for (int j = 0; j < q[c].size(); j++) q[i].push_back(q[c][j]);     }     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);       v[x].push_back(y);       v[y].push_back(x);     }     init(1, 0);     while (t--) {       int k;       scanf( %d , &k);       if (k == 1) {         int c;         scanf( %d , &c);         printf( %d n , g[c]);       } else {         int x, y;         scanf( %d %d , &x, &y);         a[x] = y;         init(1, 0);       }     }     return 0;   }   