#include <bits/stdc++.h>
using namespace std;
int val[100001];
vector<int> child[100001];
int parent[100001];
pair<int, int> edges[100001];
int n, q;
int gcd(int a, int b) {
  if (a % b == 0) return b;
  return gcd(b, a % b);
}
void show_vector(vector<int> &x) {
  for (int i = 0; i < x.size(); ++i) printf("%d ", x[i]);
  printf("\n");
}
int main() {
  scanf("%d", &n);
  scanf("%d", &q);
  int i, j;
  for (i = 1; i <= n; ++i) scanf("%d", &val[i]);
  for (i = 0; i < n - 1; ++i) {
    int x, y;
    scanf("%d %d", &x, &y);
    edges[i] = pair<int, int>(x, y);
    child[x].push_back(y);
    child[y].push_back(x);
  }
  queue<int> proc;
  proc.push(1);
  while (proc.size() > 0) {
    int f = proc.front();
    for (i = 0; i < child[f].size(); ++i) {
      if (child[f][i] != parent[f]) {
        parent[child[f][i]] = f;
        proc.push(child[f][i]);
      }
    }
    proc.pop();
  }
  for (i = 0; i < q; ++i) {
    int t, v, w;
    scanf("%d", &t);
    if (t == 1) {
      scanf("%d", &v);
      int out = -1;
      if (v != 1)
        for (j = parent[v]; j != 0; j = parent[j])
          if (gcd(val[j], val[v]) > 1) {
            out = j;
            break;
          }
      printf("%d\n", out);
    } else {
      scanf("%d %d", &v, &w);
      val[v] = w;
    }
  }
  return 0;
}
