#include <bits/stdc++.h>
using namespace std;
const int maxn = 200020;
const int maxm = 420;
const int MOd = 1e9 + 7;
const int P = 37;
int a, q, n, dad[maxn][20], der[maxn];
int beg[maxn], cnt;
int heavy[maxn], loc[maxn];
bool H[maxn];
vector<pair<int, pair<int, long long> > > w[maxn];
long long segment[1 << 19], ar[maxn];
const long long inf = (long long)1e18 + 1;
long long mul(long long x, long long y) {
  if ((long double)x * y >= inf) return inf;
  return x * y;
}
void up(int x, long long v) {
  int k = x + n - 1;
  segment[k] = v;
  for (k >>= 1; k; k >>= 1)
    segment[k] = mul(segment[k + k], segment[k + k + 1]);
}
int dfs(int n, int back, int s) {
  int ret = 1;
  dad[n][0] = back;
  der[n] = s;
  for (int i = 1; (1 << i) <= s; i++) dad[n][i] = dad[dad[n][i - 1]][i - 1];
  int maxi = 0, h = 0;
  for (int i = 0; i < w[n].size(); i++)
    if (w[n][i].second.first != back) {
      int t = dfs(w[n][i].second.first, n, s + 1);
      if (t > maxi) maxi = t, h = i;
      ret += t;
    }
  if (w[n].size() != 1) {
    swap(w[n][0], w[n][h]);
    H[w[n][0].second.first] = 1;
  }
  return ret;
}
void dfss(int n, int back, int last) {
  if (H[n] && !H[back]) last = n;
  heavy[n] = last;
  beg[n] = ++cnt;
  for (int i = 0; i < w[n].size(); i++)
    if (w[n][i].second.first != back) {
      ar[cnt + 1] = w[n][i].second.second;
      loc[w[n][i].first] = cnt + 1;
      dfss(w[n][i].second.first, n, last);
    }
}
int lca(int x, int y) {
  if (der[x] < der[y]) swap(x, y);
  for (int k = 17; k >= 0; k--)
    if ((1 << k) <= der[x] && der[dad[x][k]] > der[y]) x = dad[x][k];
  if (der[x] != der[y]) x = dad[x][0];
  for (int k = 17; k >= 0; k--)
    if ((1 << k) <= der[x] && dad[x][k] != dad[y][k])
      x = dad[x][k], y = dad[y][k];
  if (x != y) x = dad[x][0];
  return x;
}
long long T = 1;
int asd;
long long find(int l, int r) {
  long long t = 1;
  for (l += n - 1, r += n - 1; l <= r; l = (l + 1) >> 1, r = (r - 1) >> 1) {
    if (l & 1) t = mul(t, segment[l]);
    if (~r & 1) t = mul(t, segment[r]);
  }
  return t;
}
void f(int x, int y) {
  if (T == inf) return;
  while (der[x] > der[y]) {
    if (T == inf) return;
    if (H[x]) {
      if (der[heavy[x]] <= der[y]) {
        T = mul(T, find(beg[y] + 1, beg[x]));
        return;
      } else {
        T = mul(T, find(beg[heavy[x]], beg[x]));
        x = dad[heavy[x]][0];
      }
    } else {
      T = mul(T, ar[beg[x]]);
      x = dad[x][0];
    }
  }
}
int main() {
  scanf("%d %d", &a, &q);
  for (int i = 1, j, k; i < a; i++) {
    long long t;
    scanf("%d %d %lld", &j, &k, &t);
    w[j].push_back(
        pair<int, pair<int, long long> >(i, pair<int, long long>(k, t)));
    w[k].push_back(
        pair<int, pair<int, long long> >(i, pair<int, long long>(j, t)));
  }
  n = 1;
  while (n < a) n <<= 1;
  dfs(1, 0, 0);
  dfss(1, 0, 0);
  for (int i = 1; i <= n; i++)
    if (!ar[i])
      segment[i + n - 1] = 1;
    else
      segment[i + n - 1] = ar[i];
  for (int i = n - 1; i >= 1; i--)
    segment[i] = mul(segment[i + i], segment[i + i + 1]);
  while (q--) {
    int tp, x, y;
    long long v;
    scanf("%d", &tp);
    if (tp == 1) {
      scanf("%d %d %I64d", &x, &y, &v);
      T = 1;
      int h = lca(x, y);
      int uz = der[x] + der[y] - 2 * der[h];
      ++asd;
      f(x, h);
      f(y, h);
      if (T == inf)
        printf("0\n");
      else
        cout << v / T << endl;
    } else {
      scanf("%d %I64d", &x, &v);
      ar[loc[x]] = v;
      up(loc[x], v);
    }
  }
  return 0;
}
