#include <bits/stdc++.h>
using namespace std;
vector<int> g[100010];
int fa[100010];
int a[100010];
int n, m;
int gcd(int x, int y) {
  if (x < y) swap(x, y);
  return y == 0 ? x : gcd(y, x % y);
}
void dfs(int v, int p) {
  fa[v] = p;
  for (int i = 0; i < g[v].size(); i++) {
    int u = g[v][i];
    if (u == p) continue;
    dfs(u, v);
  }
}
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &a[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);
  }
  dfs(1, -1);
  while (m--) {
    int op, v, w;
    scanf("%d%d", &op, &v);
    if (op == 1) {
      int u = fa[v];
      int ans = -1;
      while (u != -1) {
        if (gcd(a[u], a[v]) > 1) {
          ans = u;
          break;
        }
        u = fa[u];
      }
      printf("%d\n", ans);
    } else {
      scanf("%d", &w);
      a[v] = w;
    }
  }
  return 0;
}
