#include <bits/stdc++.h>
using namespace std;
int head[100005], fa[100005], a[100005];
struct edge {
  int to, next;
} edges[200005];
int em;
void addedge(int u, int v) {
  edges[em].next = head[u];
  edges[em].to = v;
  head[u] = em++;
  edges[em].next = head[v];
  edges[em].to = u;
  head[v] = em++;
}
void dfs(int x, int f) {
  fa[x] = f;
  for (int e = head[x]; e != -1; e = edges[e].next) {
    int v = edges[e].to;
    if (v != f) {
      dfs(v, x);
    }
  }
}
int gcd(int a, int b) {
  if (b == 0)
    return a;
  else
    return gcd(b, a % b);
}
int main() {
  int n, q;
  scanf("%d%d", &n, &q);
  for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
  int m = n - 1;
  memset(head, -1, sizeof(head));
  while (m--) {
    int x, y;
    scanf("%d%d", &x, &y);
    addedge(x, y);
  }
  dfs(1, -1);
  while (q--) {
    int qq;
    scanf("%d", &qq);
    if (qq == 1) {
      int v;
      scanf("%d", &v);
      int in = -1;
      int tmp = fa[v];
      while (tmp != -1) {
        int g = gcd(a[tmp], a[v]);
        if (g > 1) {
          in = tmp;
          break;
        }
        tmp = fa[tmp];
      }
      printf("%d\n", in);
    } else if (qq == 2) {
      int v, w;
      scanf("%d%d", &v, &w);
      a[v] = w;
    }
  }
  return 0;
}
