#include <bits/stdc++.h>
using namespace std;
int a[100005], head[100005], e, v;
int fa[100005];
bool vst[100005];
struct E {
  int to, next;
} edge[200005];
inline void addedge(int u, int v) {
  edge[e].to = v;
  edge[e].next = head[u];
  head[u] = e++;
  edge[e].to = u;
  edge[e].next = head[v];
  head[v] = e++;
}
int gcd(int a, int b) {
  if (!b)
    return a;
  else
    return gcd(b, a % b);
}
void build_tree(int u) {
  vst[u] = 1;
  int i, k;
  for (i = head[u]; i; i = edge[i].next) {
    k = edge[i].to;
    if (vst[k]) continue;
    fa[k] = u;
    build_tree(k);
  }
}
int solve(int u) {
  if (!u) return -1;
  if (gcd(a[u], a[v]) > 1) return u;
  return solve(fa[u]);
}
int main() {
  int n, q, i, x, y;
  e = 1;
  scanf("%d%d", &n, &q);
  for (i = 1; i <= n; i++) scanf("%d", &a[i]);
  for (i = 2; i <= n; i++) scanf("%d%d", &x, &y), addedge(x, y);
  build_tree(1);
  for (i = 1; i <= q; i++) {
    int type;
    scanf("%d", &type);
    if (type == 1) {
      scanf("%d", &v);
      printf("%d\n", solve(fa[v]));
    } else {
      int w;
      scanf("%d%d", &v, &w);
      a[v] = w;
    }
  }
  return 0;
}
