#include <bits/stdc++.h>
using namespace std;
int n, m, pa[200001], h[200001], getRoot[200001], r, top;
long long x[200001], que[70], st[70];
pair<int, int> edge[200001];
vector<pair<int, long long> > g[200001];
int root(int u) {
  if (getRoot[u]) return (getRoot[u] = root(getRoot[u]));
  return u;
}
void setup() {
  int u, v;
  long long w;
  cin >> n >> m;
  for (int i = 1; i <= n - 1; i++) {
    cin >> u >> v >> w;
    edge[i] = make_pair(u, v);
    g[u].push_back(make_pair(v, w));
    g[v].push_back(make_pair(u, w));
  }
  memset(getRoot, 0, sizeof(getRoot));
}
void dfs(int u) {
  for (int i = 0; i <= int(g[u].size()) - 1; i++) {
    int v = g[u][i].first;
    long long w = g[u][i].second;
    if (v == pa[u]) continue;
    if (w == 1) getRoot[v] = root(u);
    h[v] = h[u] + 1;
    pa[v] = u;
    x[v] = w;
    dfs(v);
  }
}
void querry1() {
  int a, b, dem = 0;
  r = top = 0;
  long long y;
  cin >> a >> b >> y;
  a = root(a);
  b = root(b);
  while (a != b) {
    int xx = a, yy = b;
    if (h[xx] >= h[yy]) {
      que[++r] = x[a];
      a = root(pa[a]);
      dem++;
    }
    if (h[xx] <= h[yy]) {
      st[++top] = x[b];
      b = root(pa[b]);
      dem++;
    }
    if (dem >= 64) {
      cout << "0\n";
      return;
    }
  }
  for (int i = 1; i <= r; i++) y /= que[i];
  while (top) y /= st[top--];
  cout << y << '\n';
}
void querry2() {
  int p, u, v;
  long long c;
  cin >> p >> c;
  u = edge[p].first;
  v = edge[p].second;
  if (v == pa[u]) swap(u, v);
  if (c == 1)
    getRoot[v] = root(u);
  else
    x[v] = c;
}
void xuly() {
  int type;
  h[1] = 1;
  dfs(1);
  for (int i = 1; i <= m; i++) {
    cin >> type;
    if (type == 1)
      querry1();
    else
      querry2();
  }
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(NULL);
  cout.tie(NULL);
  setup();
  xuly();
  return 0;
}
