#include <bits/stdc++.h>
using namespace std;
int gcd(int a, int b) { return a == 0 ? b : gcd(b % a, a); }
int val[100005];
vector<int> g[100005];
int parent[100005];
void dfs(int u, int p) {
  for (__typeof((g[u]).begin()) i = ((g[u]).begin()); i != (g[u]).end(); ++i) {
    int v = *i;
    if (v == p) continue;
    parent[v] = u;
    dfs(v, u);
  }
}
int main() {
  ios_base::sync_with_stdio(0);
  int(n), (q);
  scanf("%d%d", &(n), &(q));
  ;
  for (int i = (0); i < (n); ++i) {
    int(a);
    scanf("%d", &(a));
    ;
    val[i] = a;
  }
  for (int i = (0); i < (n - 1); ++i) {
    int(a), (b);
    scanf("%d%d", &(a), &(b));
    ;
    g[a - 1].push_back(b - 1);
    g[b - 1].push_back(a - 1);
  }
  parent[0] = -2;
  dfs(0, -1);
  while (q--) {
    int(nr);
    scanf("%d", &(nr));
    ;
    if (nr == 1) {
      int(v);
      scanf("%d", &(v));
      ;
      v--;
      int u = parent[v];
      while (u != -2) {
        if (gcd(val[v], val[u]) != 1) break;
        u = parent[u];
      }
      cout << u + 1 << endl;
    } else {
      int(v), (c);
      scanf("%d%d", &(v), &(c));
      ;
      v--;
      val[v] = c;
    }
  }
  return 0;
}
