#include <bits/stdc++.h>
using namespace std;
int head[500000], no, n, q, val[500000], fa[500000];
struct ed {
  int u, v, next;
} p[2 * 500000];
int init() {
  no = 0;
  memset(head, -1, sizeof(head));
  return 0;
}
void add(int x, int y) {
  p[no].u = x;
  p[no].v = y;
  p[no].next = head[x];
  head[x] = no++;
  p[no].u = y;
  p[no].v = x;
  p[no].next = head[y];
  head[y] = no++;
}
void build_tree(int x, int pre) {
  for (int i = head[x]; i != -1; i = p[i].next) {
    int v = p[i].v;
    if (v == pre) continue;
    fa[v] = x;
    build_tree(v, x);
  }
}
int gcd(int x, int y) {
  if (!y)
    return x;
  else
    return gcd(y, x % y);
}
int slove(int x, int y) {
  if (x == 0)
    return -1;
  else if (gcd(val[x], val[y]) > 1)
    return x;
  else
    return slove(fa[x], y);
}
int main() {
  init();
  scanf("%d%d", &n, &q);
  for (int i = 1; i <= n; i++) {
    scanf("%d", val + i);
  }
  for (int i = 1; i < n; i++) {
    int x, y;
    scanf("%d%d", &x, &y);
    add(x, y);
  }
  build_tree(1, 1);
  for (int i = 1; i <= q; i++) {
    int x;
    scanf("%d", &x);
    if (x == 2) {
      int y, z;
      scanf("%d%d", &y, &z);
      val[y] = z;
    } else {
      int y;
      scanf("%d", &y);
      printf("%d\n", slove(fa[y], y));
    }
  }
  return 0;
}
