#include <bits/stdc++.h>
using namespace std;
const int nmax = 200010, lg = 18;
int pa[lg + 1][nmax];
int d[nmax], e[nmax], w[nmax];
long long x[nmax];
vector<pair<int, pair<long long, int> > > g[nmax];
long long c, y;
int a, b, n, m, z, i, t;
int where(int a) {
  int rang;
  if (a == w[a])
    rang = a;
  else
    rang = where(w[a]);
  w[a] = rang;
  return rang;
}
void unite(int a, int b) {
  a = where(a);
  b = where(b);
  w[a] = b;
}
void df(int a, int f) {
  d[a] = d[f] + 1;
  pa[0][a] = f;
  for (int j = 0; j < g[a].size(); ++j) {
    int b = g[a][j].first;
    long long c = g[a][j].second.first;
    int i = g[a][j].second.second;
    if (f == b) continue;
    if (c == 1) unite(b, a);
    e[i] = b;
    x[b] = c;
    df(b, a);
  }
}
void dp() {
  for (int i = 1; i <= lg; ++i)
    for (int j = 1; j <= n; ++j) pa[i][j] = pa[i - 1][pa[i - 1][j]];
}
int kanc(int a, int k) {
  for (int i = lg; i >= 0; --i)
    if ((1 << i) & k) a = pa[i][a];
  return a;
}
int lca(int a, int b) {
  if (d[a] < d[b]) swap(a, b);
  int q = d[a] - d[b];
  a = kanc(a, q);
  if (a == b) return a;
  for (int i = lg; i >= 0; --i)
    if (pa[i][a] - pa[i][b]) a = pa[i][a], b = pa[i][b];
  return pa[0][a];
}
int main() {
  scanf("%d", &n);
  scanf("%d", &m);
  for (i = 1; i <= n - 1; ++i) {
    scanf("%d%d%I64d", &a, &b, &c);
    g[a].push_back({b, {c, i}});
    g[b].push_back({a, {c, i}});
  }
  for (i = 1; i <= n; ++i) w[i] = i;
  df(1, 0);
  dp();
  while (m--) {
    scanf("%d", &t);
    if (t == 1) {
      scanf("%d%d%I64d", &a, &b, &y);
      z = lca(a, b);
      while (y) {
        a = where(a);
        if (d[a] <= d[z]) break;
        y /= x[a];
        a = pa[0][a];
      }
      while (y) {
        b = where(b);
        if (d[b] <= d[z]) break;
        y /= x[b];
        b = pa[0][b];
      }
      printf("%I64d\n", y);
    } else {
      scanf("%d%I64d", &i, &y);
      a = e[i];
      if (y == 1) unite(a, pa[0][a]);
      x[a] = y;
    }
  }
  return 0;
}
