#include <bits/stdc++.h>
#pragma warning(disable : 4996)
using namespace std;
int n, q;
vector<pair<long long, long long> > edge[300000];
pair<int, int> dat[300000];
int depth[300000];
int par[300000][20];
int nex[300000];
long long up[300000];
void back(int now, int parent, int rec) {
  depth[now] = parent == -1 ? 0 : depth[parent] + 1;
  par[now][0] = parent == -1 ? now : parent;
  for (int i = 1; i < 20; i++) par[now][i] = par[par[now][i - 1]][i - 1];
  for (auto e : edge[now]) {
    if (e.first == parent) continue;
    nex[e.first] = rec;
    up[e.first] = e.second;
    back(e.first, now, e.second == 1 ? rec : e.first);
  }
}
int lca(int x, int y) {
  int i, dif;
  if (depth[x] < depth[y]) swap(x, y);
  dif = depth[x] - depth[y];
  for (i = 0; i < 20; i++)
    if (dif & (1 << i)) x = par[x][i];
  if (x == y) return x;
  for (i = 19; i >= 0; i--)
    if (par[x][i] != par[y][i]) x = par[x][i], y = par[y][i];
  return par[x][0];
}
int main() {
  int i, j, k;
  cin >> n >> q;
  for (i = 0; i < n - 1; i++) {
    int x, y;
    long long z;
    scanf("%d%d%lld", &x, &y, &z), x--, y--;
    edge[x].push_back(pair<long long, long long>(y, z));
    edge[y].push_back(pair<long long, long long>(x, z));
    dat[i] = pair<int, int>(x, y);
  }
  back(0, -1, -1);
  for (i = 0; i < q; i++) {
    long long x, y, z;
    scanf("%lld", &x);
    if (x == 1) {
      scanf("%lld%lld%lld", &x, &y, &z), x--, y--;
      int u = lca(x, y);
      int now = x, past = -1;
      while (z && now != -1 && depth[now] > depth[u]) {
        if (up[now] == 1) {
          if (past != -1) nex[past] = nex[now];
        }
        z /= up[now];
        past = now;
        now = nex[now];
      }
      now = y;
      past = -1;
      while (z && now != -1 && depth[now] > depth[u]) {
        if (up[now] == 1) {
          if (past != -1) nex[past] = nex[now];
        }
        z /= up[now];
        past = now;
        now = nex[now];
      }
      printf("%lld\n", z);
    } else {
      scanf("%lld%lld", &x, &y), x--;
      if (depth[dat[x].first] > depth[dat[x].second])
        up[dat[x].first] = y;
      else
        up[dat[x].second] = y;
    }
  }
  return 0;
}
