#include <bits/stdc++.h>
using namespace std;
const int MAXN = 100010, MAXA = 2000000;
int head[MAXN], nxt[MAXN << 1], to[MAXN << 1], edgeCnt = 1;
int prime_factor[MAXA + 1], factors[70], numFactors;
int value[MAXN], nodeTime[MAXN], dfs_time = 0;
int n, m;
vector<pair<int, int> > nodes[MAXA + 1];
pair<int, int> ans[MAXN];
void sieve() {
  for (int i = 0; i < (MAXA + 1); i++) prime_factor[i] = i;
  for (long long i = 2; i <= MAXA; i++)
    if (prime_factor[i] == i) {
      for (long long j = i * i; j <= MAXA; j += i) prime_factor[j] = i;
    }
}
void factorize(int n) {
  numFactors = 0;
  while (n > 1) {
    int p = prime_factor[n];
    factors[numFactors++] = p;
    while (n % p == 0) n /= p;
  }
}
void add_edge(int a, int b) {
  to[edgeCnt] = b;
  nxt[edgeCnt] = head[a];
  head[a] = edgeCnt++;
}
void addBiEdge(int a, int b) {
  add_edge(a, b);
  add_edge(b, a);
}
void dfs(int u, int p = 0, int depth = 0) {
  ans[u] = {-1, -1};
  factorize(value[u]);
  for (int i = 0; i < (numFactors); i++) {
    if (!nodes[factors[i]].empty())
      if (ans[u].first < nodes[factors[i]].back().first)
        ans[u] = nodes[factors[i]].back();
    nodes[factors[i]].push_back(make_pair(depth, u));
  }
  for (int e = head[u]; e; e = nxt[e])
    if (to[e] != p) dfs(to[e], u, depth + 1);
  factorize(value[u]);
  for (int i = 0; i < (numFactors); i++) nodes[factors[i]].pop_back();
}
int main() {
  sieve();
  int a, b, type, u, v;
  scanf("%d %d", &n, &m);
  for (int i = 0; i < (n); i++) scanf("%d", value + i + 1);
  for (int i = 0; i < (n - 1); i++) {
    scanf("%d %d", &a, &b);
    addBiEdge(a, b);
  }
  dfs(1);
  while (m--) {
    scanf("%d %d", &type, &u);
    if (type == 2) {
      scanf("%d", &v);
      value[u] = v;
      dfs(1);
    } else
      printf("%d\n", ans[u].second);
  }
  return 0;
}
