#include <bits/stdc++.h>
using namespace std;
template <typename T>
T read1() {
  T t = 0;
  char k;
  bool vis = 0;
  do (k = getchar()) == '-' && (vis = 1);
  while ('0' > k || k > '9');
  while ('0' <= k && k <= '9')
    t = (t << 3) + (t << 1) + (k ^ '0'), k = getchar();
  return vis ? -t : t;
}
vector<int> G[200005], N[200005];
vector<long long> V[200005];
int s, q, f[200005], h[200005], d[200005], fr[200005];
long long v[200005];
void dfs(int n, int fa) {
  h[n] = h[fa] + 1;
  d[n] = fa;
  for (int i = 0; i < G[n].size(); ++i)
    if (G[n][i] ^ fa) {
      v[G[n][i]] = V[n][i];
      if (V[n][i] == 1) f[G[n][i]] = f[n];
      fr[N[n][i]] = G[n][i];
      dfs(G[n][i], n);
    }
}
int Find(int x) { return x ^ f[x] ? f[x] = Find(f[x]) : x; }
long long query(int x, int y, long long z) {
  x = Find(x);
  y = Find(y);
  while (z && x != y) {
    if (h[x] < h[y]) swap(x, y);
    z /= v[x];
    x = Find(d[x]);
  }
  return z;
}
int main() {
  s = read1<long long>(), q = read1<long long>();
  for (int i = 1; i <= s; ++i) f[i] = i;
  for (int i = 1; i < s; ++i) {
    int u = read1<long long>(), v = read1<long long>();
    long long t = read1<long long>();
    G[u].push_back(v);
    G[v].push_back(u);
    V[u].push_back(t);
    V[v].push_back(t);
    N[u].push_back(i);
    N[v].push_back(i);
  }
  dfs(1, 0);
  while (q--)
    if (read1<long long>() & 1) {
      int u = read1<long long>(), v = read1<long long>();
      printf("%lld\n", query(u, v, read1<long long>()));
    } else {
      int x = read1<long long>();
      long long t = read1<long long>();
      if (v[fr[x]] == t) continue;
      v[fr[x]] = t;
      if (t == 1) f[fr[x]] = d[fr[x]];
    }
  return 0;
}
