#include <bits/stdc++.h>
using namespace std;
long long fa[400010], f[400010][20], n, m, x_1, x_2, x_3, x_4, x_5, dep[400010],
    lop[400010], from[400010], ver[400010], head[400010], nex[400010],
    edge[400010], cnt;
template <class t>
inline t read(t &x) {
  char c = getchar();
  bool f = 0;
  x = 0;
  while (!isdigit(c)) f |= c == '-', c = getchar();
  while (isdigit(c)) x = (x << 1) + (x << 3) + (c ^ 48), c = getchar();
  if (f) x = -x;
  return x;
}
template <class t>
inline void write(t x) {
  if (x < 0)
    putchar('-'), write(-x);
  else {
    if (x > 9) write(x / 10);
    putchar('0' + x % 10);
  }
}
template <class t>
inline void writeln(t x) {
  write(x);
  putchar('\n');
  return;
}
template <class t>
inline void write_blank(t x) {
  write(x);
  putchar(' ');
  return;
}
void add(long long u, long long v, long long w) {
  from[++cnt] = u;
  ver[cnt] = v;
  edge[cnt] = w;
  nex[cnt] = head[u];
  head[u] = cnt;
}
long long LCA(long long x, long long y) {
  if (dep[x] < dep[y]) {
    swap(x, y);
  }
  if (dep[x] != dep[y]) {
    for (long long i = 16; i >= 0; i--) {
      if (dep[f[x][i]] >= dep[y]) {
        x = f[x][i];
      }
    }
  }
  if (x == y) {
    return y;
  }
  for (long long i = 16; i >= 0; i--) {
    if (f[x][i] != f[y][i]) {
      x = f[x][i], y = f[y][i];
    }
  }
  return f[y][0];
}
long long find(long long k) {
  if (fa[k] == k) {
    return k;
  }
  return fa[k] = find(fa[k]);
}
void dfs(long long x, long long fax) {
  f[x][0] = fax;
  dep[x] = dep[fax] + 1;
  for (long long j = 1; j <= 16; j++) {
    f[x][j] = f[f[x][j - 1]][j - 1];
  }
  for (long long j = head[x]; j; j = nex[j]) {
    long long y = ver[j];
    if (y == fax) {
      continue;
    }
    lop[y] = j;
    if (edge[j] == 1) {
      fa[y] = fa[find(x)];
    }
    dfs(y, x);
  }
  return;
}
void solve(long long x, long long y, long long &z) {
  for (long long w = f[x][0]; x != 1; x = w, w = f[x][0]) {
    if (find(x) != x) {
      x = fa[x];
      w = f[x][0];
    }
    if (dep[y] > dep[w]) {
      return;
    }
    if (x != 1) {
      z /= edge[lop[x]];
    }
    if (z == 0) {
      return;
    }
  }
}
signed main() {
  read(n);
  read(m);
  for (long long i = 1; i <= n - 1; i++) {
    read(x_1);
    read(x_2);
    read(x_3);
    add(x_1, x_2, x_3);
    add(x_2, x_1, x_3);
  }
  for (long long i = 1; i <= n; i++) {
    fa[i] = i;
  }
  dfs(1, 1);
  for (long long i = 1; i <= m; i++) {
    read(x_1);
    if (x_1 == 1) {
      read(x_2);
      read(x_3);
      read(x_4);
      x_5 = LCA(x_2, x_3);
      if (x_2 != x_5) solve(x_2, x_5, x_4);
      if (x_4 != 0)
        if (x_3 != x_5) solve(x_3, x_5, x_4);
      writeln(x_4);
    }
    if (x_1 == 2) {
      read(x_2);
      read(x_3);
      edge[x_2 * 2] = x_3;
      edge[x_2 * 2 - 1] = x_3;
      if (x_3 == 1) {
        if (f[ver[x_2 * 2 - 1]][0] == from[x_2 * 2 - 1]) {
          fa[find(ver[x_2 * 2 - 1])] = fa[find(from[x_2 * 2 - 1])];
          continue;
        }
        fa[find(from[x_2 * 2 - 1])] = fa[find(ver[x_2 * 2 - 1])];
      }
    }
  }
  return 0;
}
