#include <bits/stdc++.h>
using namespace std;
const int inf = 0x3f3f3f3f;
const long long infl = 0x3f3f3f3f3f3f3f3fLL;
template <class T>
void rd(T &a) {
  char ch = getchar();
  bool ng = 0;
  a = 0;
  for (; ch < '0' || ch > '9'; ch = getchar())
    if (ch == '-') ng = 1;
  for (; ch >= '0' && ch <= '9'; ch = getchar())
    a = (a << 1) + (a << 3) + (ch ^ '0');
  if (ng) a = ~a + 1;
}
template <class T>
void wrt(T a) {
  if (a < 0) {
    putchar('-');
    wrt(~a + 1);
  } else {
    if (a > 9) wrt(a / 10);
    putchar(a % 10 ^ '0');
  }
}
const int Maxn = 2e5 + 5;
int n, q, p[Maxn];
vector<pair<int, int> > G[Maxn];
struct dsu {
  int up[Maxn];
  void init() {
    for (int i = 1; i <= n; ++i) up[i] = i;
  }
  int go(int u) { return (up[u] == u) ? u : (up[u] = go(up[u])); }
} T;
struct edge {
  int u, v;
  long long w;
  edge() {}
  edge(int u, int v, long long w) : u(u), v(v), w(w) {}
} E[Maxn];
int ind[Maxn];
int tin[Maxn], tout[Maxn], timer = 0;
bool is_anc(int u, int v) { return tin[u] <= tin[v] && tout[u] >= tout[v]; }
void dfs(int u) {
  tin[u] = ++timer;
  for (int i = 0; i < (int)((G[u]).size()); ++i) {
    int v = G[u][i].first, id = G[u][i].second;
    if (v != p[u]) p[v] = u, ind[v] = id, dfs(v);
  }
  tout[u] = timer;
}
inline void upd(int id, long long val) {
  E[id].w = val;
  if (val == 1) T.up[E[id].v] = E[id].u;
}
long long query(int u, int v, long long val) {
  int cur = T.go(u);
  while (val && is_anc(cur, u) && !is_anc(cur, v)) {
    val /= E[ind[cur]].w;
    cur = T.go(p[cur]);
  }
  if (!val) return 0;
  cur = T.go(v);
  while (val && !is_anc(cur, u) && is_anc(cur, v)) {
    val /= E[ind[cur]].w;
    cur = T.go(p[cur]);
  }
  return val;
}
int main() {
  rd(n), rd(q);
  for (int i = 1; i < n; ++i) {
    int u, v;
    long long w;
    rd(u), rd(v), rd(w);
    G[u].push_back(pair<int, int>(v, i));
    G[v].push_back(pair<int, int>(u, i));
    E[i] = edge(u, v, w);
  }
  dfs(1), T.init();
  for (int i = 1; i < n; ++i)
    if (p[E[i].u] == E[i].v) swap(E[i].u, E[i].v);
  for (int i = 1; i < n; ++i) upd(i, E[i].w);
  while (q--) {
    int tp, u;
    rd(tp), rd(u);
    if (tp & 1) {
      int v;
      long long w;
      rd(v), rd(w);
      wrt(query(u, v, w));
      puts("");
    } else {
      long long v;
      rd(v);
      upd(u, v);
    }
  }
  return 0;
}
