#include <bits/stdc++.h>
using namespace std;
inline long long gi() {
  long long x = 0, f = 0;
  char ch = getchar();
  while (!isdigit(ch)) {
    f |= ch == '-', ch = getchar();
  }
  while (isdigit(ch)) {
    x = x * 10 + ch - 48, ch = getchar();
  }
  return f ? -x : x;
}
inline void pi(long long x) {
  if (x < 0) putchar('-'), x = -x;
  if (x > 9) pi(x / 10);
  putchar(x % 10 + 48);
}
inline void pib(long long x) {
  pi(x);
  putchar(' ');
}
inline void pin(long long x) {
  pi(x);
  putchar('\n');
}
const long long N = 2e5 + 5, M = N << 1;
long long lnk[N], nxt[M], to[M], ec, from[M], w[M];
inline void add(long long u, long long v, long long c) {
  to[++ec] = v;
  from[ec] = u;
  w[ec] = c;
  nxt[ec] = lnk[u];
  lnk[u] = ec;
}
long long fa[N][25], dep[N], f[N], val[N];
inline long long find(long long x) { return x == f[x] ? x : f[x] = find(f[x]); }
void dfs(long long u, long long Fa) {
  fa[u][0] = Fa;
  dep[u] = dep[Fa] + 1;
  for (register long long i = (1); i <= (24); ++i)
    fa[u][i] = fa[fa[u][i - 1]][i - 1];
  for (register long long i = lnk[u]; i; i = nxt[i]) {
    long long v = to[i];
    if (v == Fa) continue;
    if (w[i] == 1) f[v] = find(u);
    val[v] = w[i];
    dfs(v, u);
  }
}
inline long long lca(long long u, long long v) {
  if (dep[u] < dep[v]) swap(u, v);
  for (register long long i = (24); i >= (0); --i)
    if (dep[fa[u][i]] >= dep[v]) u = fa[u][i];
  if (u == v) return u;
  for (register long long i = (24); i >= (0); --i)
    if (fa[u][i] != fa[v][i]) u = fa[u][i], v = fa[v][i];
  return fa[u][0];
}
long long n;
signed main() {
  n = gi();
  long long q = gi();
  for (register long long i = (1); i <= (n - 1); ++i) {
    long long u = gi(), v = gi(), w = gi();
    add(u, v, w);
    add(v, u, w);
  }
  for (register long long i = (1); i <= (n); ++i) f[i] = i;
  dfs(1, 0);
  while (q--) {
    long long op = gi();
    if (op == 1) {
      long long x = gi(), y = gi(), z = gi();
      long long L = lca(x, y), a = x, b = y;
      while (dep[a] > dep[L] && z) {
        if (val[a]) z /= val[a];
        a = find(fa[a][0]);
      }
      while (dep[b] > dep[L] && z) {
        if (val[b]) z /= val[b];
        b = find(fa[b][0]);
      }
      pin(z);
    } else {
      long long x = gi(), y = gi(), son;
      long long u = from[x << 1], v = to[x << 1];
      if (fa[u][0] == v)
        son = u;
      else
        son = v;
      val[son] = y;
      if (val[son] == 1) f[son] = find(fa[son][0]);
    }
  }
}
