#include <bits/stdc++.h>
using namespace std;
inline long long read() {
  long long w = 0, s = 1;
  char c = getchar();
  while (!isdigit(c)) {
    s = (c == '-') ? -1 : 1;
    c = getchar();
  }
  while (isdigit(c)) {
    w = (w << 3) + (w << 1) + c - '0';
    c = getchar();
  }
  return w * s;
}
const int N = 200005;
long long pre[N], cnt;
struct Edge {
  long long nxt, to, wei, from;
};
Edge edge[N << 1];
void add_for(long long u, long long v, long long w) {
  edge[++cnt].nxt = pre[u];
  edge[cnt].to = v;
  edge[cnt].wei = w;
  edge[cnt].from = u;
  pre[u] = cnt;
}
long long f[N][21], dep[N], fa[N], va[N];
long long find(long long x) { return fa[x] == x ? x : fa[x] = find(fa[x]); }
void search(long long u, long long grt) {
  f[u][0] = grt;
  dep[u] = dep[grt] + 1;
  for (long long i = 1; i <= 17; i++) {
    f[u][i] = f[f[u][i - 1]][i - 1];
  }
  for (long long i = pre[u]; i > 0; i = edge[i].nxt) {
    long long v = edge[i].to, w = edge[i].wei;
    if (v != grt) {
      if (w == 1) {
        fa[v] = find(u);
      }
      va[v] = w;
      search(v, u);
    }
  }
}
long long LCA(long long u, long long v) {
  if (dep[u] < dep[v]) {
    swap(u, v);
  }
  for (long long i = 17; i >= 0; i--) {
    if (dep[f[u][i]] >= dep[v]) {
      u = f[u][i];
    }
    if (u == v) {
      return u;
    }
  }
  for (long long i = 17; i >= 0; i--) {
    if (f[u][i] != f[v][i]) {
      u = f[u][i];
      v = f[v][i];
    }
  }
  return f[u][0];
}
long long n, q;
int main() {
  n = read();
  q = read();
  long long u, v, w;
  for (long long i = 1; i < n; i++) {
    u = read();
    v = read();
    w = read();
    add_for(u, v, w);
    add_for(v, u, w);
  }
  for (long long i = 1; i <= n; i++) {
    fa[i] = i;
  }
  search(1, 0);
  long long opt, x, y, z;
  for (long long p = 1; p <= q; p++) {
    opt = read();
    if (opt == 1) {
      x = read();
      y = read();
      z = read();
      long long anc = LCA(x, y), a = x, b = y;
      while (dep[a] > dep[anc] && z) {
        z /= va[a];
        a = find(f[a][0]);
      }
      while (dep[b] > dep[anc] && z) {
        z /= va[b];
        b = find(f[b][0]);
      }
      printf("%lld\n", z);
    } else {
      x = read();
      y = read();
      long long u = edge[x << 1].from, v = edge[x << 1].to;
      if (f[u][0] == v) {
        z = u;
      } else {
        z = v;
      }
      va[z] = y;
      if (va[z] == 1) {
        fa[z] = find(f[z][0]);
      }
    }
  }
  return 0;
}
