#include <bits/stdc++.h>
const int inf = 0x3f3f3f;
const long long INF = 1ll << 61;
using namespace std;
int n, q;
int val[100000 + 55];
int father[100000 + 55];
vector<int> G[100000 + 55];
void init() { memset(val, 0, sizeof(val)); }
bool input() {
  while (cin >> n >> q) {
    for (int i = 1; i <= n; i++) scanf("%d", &val[i]);
    for (int i = 1; i < n; i++) {
      int u, v;
      scanf("%d %d", &u, &v);
      G[u].push_back(v);
      G[v].push_back(u);
    }
    return false;
  }
  return true;
}
int gcd(int a, int b) { return b == 0 ? a : gcd(b, a % b); }
void dfs(int u, int pre) {
  father[u] = pre;
  for (int i = 0; i < G[u].size(); i++) {
    int v = G[u][i];
    if (v != pre) dfs(v, u);
  }
}
int find(int x) {
  int v = val[x];
  x = father[x];
  while (x) {
    if (gcd(val[x], v) > 1) return x;
    x = father[x];
  }
  return -1;
}
void cal() {
  dfs(1, -1);
  while (q--) {
    int type;
    scanf("%d", &type);
    if (type == 1) {
      int v;
      scanf("%d", &v);
      printf("%d\n", find(v));
    } else {
      int v, w;
      scanf("%d %d", &v, &w);
      val[v] = w;
    }
  }
}
void output() {}
int main() {
  while (true) {
    init();
    if (input()) return 0;
    cal();
    output();
  }
  return 0;
}
