#include <bits/stdc++.h>
struct Edge {
  int32_t src, dst;
  int32_t index;
  Edge() {}
  Edge(int32_t src_, int32_t dst_, int32_t index_) {
    src = src_;
    dst = dst_;
    index = index_;
  }
};
int32_t time_ = 0;
void dfs(int32_t vertex, int32_t parent, std::vector<Edge>* graph,
         int32_t depth, int32_t* depths, int32_t* tin, int32_t* tout) {
  tin[vertex] = time_++;
  depths[vertex] = depth;
  for (int32_t i = 0; i < graph[vertex].size(); i++)
    if (graph[vertex][i].dst != parent)
      dfs(graph[vertex][i].dst, vertex, graph, depth + 1, depths, tin, tout);
  tout[vertex] = time_;
}
bool is_ancestor(int32_t v1, int32_t v2, int32_t* tin, int32_t* tout) {
  return tin[v1] <= tin[v2] && tout[v2] <= tout[v1];
}
void build_ancestors(int32_t vertex, int32_t parent, int32_t** ancestors,
                     std::vector<Edge>* graph) {
  ancestors[vertex] = new int32_t[20];
  ancestors[vertex][0] = 0;
  ancestors[vertex][1] = parent;
  for (int32_t i = 2; i < 20; i++) {
    if (ancestors[vertex][i - 1] == -1)
      ancestors[vertex][i] = -1;
    else
      ancestors[vertex][i] = ancestors[ancestors[vertex][i - 1]][i - 1];
  }
  for (int32_t i = 0; i < graph[vertex].size(); i++)
    if (graph[vertex][i].dst != parent)
      build_ancestors(graph[vertex][i].dst, vertex, ancestors, graph);
}
int32_t kth_ancestor(int32_t vertex, int32_t** ancestors, int32_t k) {
  if (k == 0) return vertex;
  if (k == 1) return ancestors[vertex][1];
  int32_t best_ind = 1;
  for (int32_t i = 2; i < 20; i++)
    if (k - (1 << (i - 1)) >= 0)
      best_ind = i;
    else
      break;
  return kth_ancestor(ancestors[vertex][best_ind], ancestors,
                      k - (1 << (best_ind - 1)));
}
int32_t lca(int32_t v1, int32_t v2, int32_t* tin, int32_t* tout,
            int32_t** ancestors) {
  if (is_ancestor(v1, v2, tin, tout)) return v1;
  if (is_ancestor(v2, v1, tin, tout)) return v2;
  for (int32_t i = 19; i >= 0; i--) {
    if (ancestors[v1][i] != -1 && !is_ancestor(ancestors[v1][i], v2, tin, tout))
      v1 = ancestors[v1][i];
  }
  return ancestors[v1][1];
}
int32_t* dsu_parents;
int32_t* dsu_top;
int32_t* depths;
int32_t find_root(int32_t vertex) {
  if (dsu_parents[vertex] == vertex) return vertex;
  return dsu_parents[vertex] = find_root(dsu_parents[vertex]);
}
bool join(int32_t v1, int32_t v2) {
  int32_t root1 = find_root(v1);
  int32_t root2 = find_root(v2);
  if (root1 == root2) return false;
  dsu_parents[root1] = root2;
  if (depths[dsu_top[root1]] < depths[dsu_top[root2]])
    dsu_top[root2] = dsu_top[root1];
  return true;
}
int main() {
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);
  std::cout.tie(0);
  int32_t n, m;
  std::cin >> n >> m;
  std::vector<Edge>* graph = new std::vector<Edge>[n];
  int64_t* edge_weights = new int64_t[n - 1];
  Edge* edges = new Edge[n - 1];
  std::unordered_map<int64_t, int32_t> edges_map;
  edges_map.max_load_factor(0.25);
  edges_map.reserve(n - 1);
  for (int32_t i = 0; i < n - 1; i++) {
    int32_t src, dst;
    int64_t weight;
    std::cin >> src >> dst >> weight;
    src--;
    dst--;
    graph[src].emplace_back(src, dst, i);
    graph[dst].emplace_back(dst, src, i);
    edge_weights[i] = weight;
    edges[i] = {src, dst, i};
    edges_map[(int64_t)src * n + dst] = i;
    edges_map[(int64_t)dst * n + src] = i;
  }
  depths = new int32_t[n];
  int32_t *tin = new int32_t[n], *tout = new int32_t[n];
  dfs(0, -1, graph, 0, depths, tin, tout);
  int32_t** ancestors = new int32_t*[n];
  build_ancestors(0, -1, ancestors, graph);
  dsu_parents = new int32_t[n];
  dsu_top = new int32_t[n];
  for (int32_t i = 0; i < n; i++) {
    dsu_parents[i] = i;
    dsu_top[i] = i;
  }
  for (int32_t i = 0; i < n; i++) {
    std::vector<int32_t> neighbors_1;
    for (int32_t j = 0; j < graph[i].size(); j++)
      if (edge_weights[graph[i][j].index] == 1)
        neighbors_1.push_back(graph[i][j].dst);
    for (int32_t j = 0; j < neighbors_1.size(); j++) join(i, neighbors_1[j]);
  }
  for (int32_t q = 0; q < m; q++) {
    int32_t type;
    std::cin >> type;
    if (type == 1) {
      int32_t v1, v2;
      int64_t num;
      std::cin >> v1 >> v2 >> num;
      v1--;
      v2--;
      if (depths[v1] < depths[v2]) {
        int32_t tmp = v1;
        v1 = v2;
        v2 = tmp;
      }
      int32_t lca_cur = lca(v1, v2, tin, tout, ancestors);
      int32_t cur = v1;
      int32_t num_ancestor = -1;
      while (cur != v2) {
        if (num == 0) break;
        int32_t next_dir = num_ancestor == -1
                               ? ancestors[cur][1]
                               : kth_ancestor(v2, ancestors, num_ancestor - 1);
        int32_t next_edge = edges_map[(int64_t)cur * n + next_dir];
        num /= edge_weights[next_edge];
        if (num_ancestor == -1) {
          cur = dsu_top[find_root(next_dir)];
          if (depths[dsu_top[find_root(next_dir)]] <= depths[lca_cur])
            num_ancestor = depths[v2] - depths[cur];
        } else {
          int32_t num_ancestor_cur = 0;
          int32_t cur2 = v2;
          for (int32_t i = 19; i > 0; i--) {
            if (ancestors[cur2][i] != -1 &&
                depths[ancestors[cur2][i]] >= depths[dsu_top[find_root(cur)]] &&
                find_root(ancestors[cur2][i]) != find_root(cur)) {
              num_ancestor_cur += 1 << (i - 1);
              cur2 = ancestors[cur2][i];
            }
          }
          num_ancestor_cur++;
          num_ancestor = num_ancestor_cur;
          int32_t next = kth_ancestor(v2, ancestors, num_ancestor);
          if (depths[next] < depths[next_dir]) {
            num_ancestor--;
            next = next_dir;
          }
          cur = next;
        }
      }
      std::cout << num << "\n";
    } else {
      int32_t ind;
      int64_t new_val;
      std::cin >> ind >> new_val;
      ind--;
      edge_weights[ind] = new_val;
      if (new_val == 1) {
        join(edges[ind].src, edges[ind].dst);
      }
    }
  }
  return 0;
}

### Prompt

Please provide a CPP coded solution to the problem described below:

Bogdan has a birthday today and mom gave him a tree consisting of n vertecies. For every edge of the tree i, some number xi was written on it. In case you forget, a tree is a connected non-directed graph without cycles. After the present was granted, m guests consecutively come to Bogdan's party. When the i-th guest comes, he performs exactly one of the two possible operations: 

  1. Chooses some number yi, and two vertecies ai and bi. After that, he moves along the edges of the tree from vertex ai to vertex bi using the shortest path (of course, such a path is unique in the tree). Every time he moves along some edge j, he replaces his current number yi by <image>, that is, by the result of integer division yi div xj. 
  2. Chooses some edge pi and replaces the value written in it xpi by some positive integer ci < xpi. 



As Bogdan cares about his guests, he decided to ease the process. Write a program that performs all the operations requested by guests and outputs the resulting value yi for each i of the first type.

Input

The first line of the input contains integers, n and m (2 ≤ n ≤ 200 000, 1 ≤ m ≤ 200 000) — the number of vertecies in the tree granted to Bogdan by his mom and the number of guests that came to the party respectively.

Next n - 1 lines contain the description of the edges. The i-th of these lines contains three integers ui, vi and xi (1 ≤ ui, vi ≤ n, ui ≠ vi, 1 ≤ xi ≤ 1018), denoting an edge that connects vertecies ui and vi, with the number xi initially written on it.

The following m lines describe operations, requested by Bogdan's guests. Each description contains three or four integers and has one of the two possible forms: 

  * 1 ai bi yi corresponds to a guest, who chooses the operation of the first type. 
  * 2 pi ci corresponds to a guests, who chooses the operation of the second type. 

It is guaranteed that all the queries are correct, namely 1 ≤ ai, bi ≤ n, 1 ≤ pi ≤ n - 1, 1 ≤ yi ≤ 1018 and 1 ≤ ci < xpi, where xpi represents a number written on edge pi at this particular moment of time that is not necessarily equal to the initial value xpi, as some decreases may have already been applied to it. The edges are numbered from 1 to n - 1 in the order they appear in the input.

Output

For each guest who chooses the operation of the first type, print the result of processing the value yi through the path from ai to bi.

Examples

Input

6 6
1 2 1
1 3 7
1 4 4
2 5 5
2 6 2
1 4 6 17
2 3 2
1 4 6 17
1 5 5 20
2 4 1
1 5 1 3


Output

2
4
20
3


Input

5 4
1 2 7
1 3 3
3 4 2
3 5 5
1 4 2 100
1 5 4 1
2 2 2
1 1 3 4


Output

2
0
2

Note

Initially the tree looks like this: 

<image>

The response to the first query is: <image> = 2

After the third edge is changed, the tree looks like this: 

<image>

The response to the second query is: <image> = 4

In the third query the initial and final vertex coincide, that is, the answer will be the initial number 20.

After the change in the fourth edge the tree looks like this: 

<image>

In the last query the answer will be: <image> = 3

### Response

```cpp
#include <bits/stdc++.h>
struct Edge {
  int32_t src, dst;
  int32_t index;
  Edge() {}
  Edge(int32_t src_, int32_t dst_, int32_t index_) {
    src = src_;
    dst = dst_;
    index = index_;
  }
};
int32_t time_ = 0;
void dfs(int32_t vertex, int32_t parent, std::vector<Edge>* graph,
         int32_t depth, int32_t* depths, int32_t* tin, int32_t* tout) {
  tin[vertex] = time_++;
  depths[vertex] = depth;
  for (int32_t i = 0; i < graph[vertex].size(); i++)
    if (graph[vertex][i].dst != parent)
      dfs(graph[vertex][i].dst, vertex, graph, depth + 1, depths, tin, tout);
  tout[vertex] = time_;
}
bool is_ancestor(int32_t v1, int32_t v2, int32_t* tin, int32_t* tout) {
  return tin[v1] <= tin[v2] && tout[v2] <= tout[v1];
}
void build_ancestors(int32_t vertex, int32_t parent, int32_t** ancestors,
                     std::vector<Edge>* graph) {
  ancestors[vertex] = new int32_t[20];
  ancestors[vertex][0] = 0;
  ancestors[vertex][1] = parent;
  for (int32_t i = 2; i < 20; i++) {
    if (ancestors[vertex][i - 1] == -1)
      ancestors[vertex][i] = -1;
    else
      ancestors[vertex][i] = ancestors[ancestors[vertex][i - 1]][i - 1];
  }
  for (int32_t i = 0; i < graph[vertex].size(); i++)
    if (graph[vertex][i].dst != parent)
      build_ancestors(graph[vertex][i].dst, vertex, ancestors, graph);
}
int32_t kth_ancestor(int32_t vertex, int32_t** ancestors, int32_t k) {
  if (k == 0) return vertex;
  if (k == 1) return ancestors[vertex][1];
  int32_t best_ind = 1;
  for (int32_t i = 2; i < 20; i++)
    if (k - (1 << (i - 1)) >= 0)
      best_ind = i;
    else
      break;
  return kth_ancestor(ancestors[vertex][best_ind], ancestors,
                      k - (1 << (best_ind - 1)));
}
int32_t lca(int32_t v1, int32_t v2, int32_t* tin, int32_t* tout,
            int32_t** ancestors) {
  if (is_ancestor(v1, v2, tin, tout)) return v1;
  if (is_ancestor(v2, v1, tin, tout)) return v2;
  for (int32_t i = 19; i >= 0; i--) {
    if (ancestors[v1][i] != -1 && !is_ancestor(ancestors[v1][i], v2, tin, tout))
      v1 = ancestors[v1][i];
  }
  return ancestors[v1][1];
}
int32_t* dsu_parents;
int32_t* dsu_top;
int32_t* depths;
int32_t find_root(int32_t vertex) {
  if (dsu_parents[vertex] == vertex) return vertex;
  return dsu_parents[vertex] = find_root(dsu_parents[vertex]);
}
bool join(int32_t v1, int32_t v2) {
  int32_t root1 = find_root(v1);
  int32_t root2 = find_root(v2);
  if (root1 == root2) return false;
  dsu_parents[root1] = root2;
  if (depths[dsu_top[root1]] < depths[dsu_top[root2]])
    dsu_top[root2] = dsu_top[root1];
  return true;
}
int main() {
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);
  std::cout.tie(0);
  int32_t n, m;
  std::cin >> n >> m;
  std::vector<Edge>* graph = new std::vector<Edge>[n];
  int64_t* edge_weights = new int64_t[n - 1];
  Edge* edges = new Edge[n - 1];
  std::unordered_map<int64_t, int32_t> edges_map;
  edges_map.max_load_factor(0.25);
  edges_map.reserve(n - 1);
  for (int32_t i = 0; i < n - 1; i++) {
    int32_t src, dst;
    int64_t weight;
    std::cin >> src >> dst >> weight;
    src--;
    dst--;
    graph[src].emplace_back(src, dst, i);
    graph[dst].emplace_back(dst, src, i);
    edge_weights[i] = weight;
    edges[i] = {src, dst, i};
    edges_map[(int64_t)src * n + dst] = i;
    edges_map[(int64_t)dst * n + src] = i;
  }
  depths = new int32_t[n];
  int32_t *tin = new int32_t[n], *tout = new int32_t[n];
  dfs(0, -1, graph, 0, depths, tin, tout);
  int32_t** ancestors = new int32_t*[n];
  build_ancestors(0, -1, ancestors, graph);
  dsu_parents = new int32_t[n];
  dsu_top = new int32_t[n];
  for (int32_t i = 0; i < n; i++) {
    dsu_parents[i] = i;
    dsu_top[i] = i;
  }
  for (int32_t i = 0; i < n; i++) {
    std::vector<int32_t> neighbors_1;
    for (int32_t j = 0; j < graph[i].size(); j++)
      if (edge_weights[graph[i][j].index] == 1)
        neighbors_1.push_back(graph[i][j].dst);
    for (int32_t j = 0; j < neighbors_1.size(); j++) join(i, neighbors_1[j]);
  }
  for (int32_t q = 0; q < m; q++) {
    int32_t type;
    std::cin >> type;
    if (type == 1) {
      int32_t v1, v2;
      int64_t num;
      std::cin >> v1 >> v2 >> num;
      v1--;
      v2--;
      if (depths[v1] < depths[v2]) {
        int32_t tmp = v1;
        v1 = v2;
        v2 = tmp;
      }
      int32_t lca_cur = lca(v1, v2, tin, tout, ancestors);
      int32_t cur = v1;
      int32_t num_ancestor = -1;
      while (cur != v2) {
        if (num == 0) break;
        int32_t next_dir = num_ancestor == -1
                               ? ancestors[cur][1]
                               : kth_ancestor(v2, ancestors, num_ancestor - 1);
        int32_t next_edge = edges_map[(int64_t)cur * n + next_dir];
        num /= edge_weights[next_edge];
        if (num_ancestor == -1) {
          cur = dsu_top[find_root(next_dir)];
          if (depths[dsu_top[find_root(next_dir)]] <= depths[lca_cur])
            num_ancestor = depths[v2] - depths[cur];
        } else {
          int32_t num_ancestor_cur = 0;
          int32_t cur2 = v2;
          for (int32_t i = 19; i > 0; i--) {
            if (ancestors[cur2][i] != -1 &&
                depths[ancestors[cur2][i]] >= depths[dsu_top[find_root(cur)]] &&
                find_root(ancestors[cur2][i]) != find_root(cur)) {
              num_ancestor_cur += 1 << (i - 1);
              cur2 = ancestors[cur2][i];
            }
          }
          num_ancestor_cur++;
          num_ancestor = num_ancestor_cur;
          int32_t next = kth_ancestor(v2, ancestors, num_ancestor);
          if (depths[next] < depths[next_dir]) {
            num_ancestor--;
            next = next_dir;
          }
          cur = next;
        }
      }
      std::cout << num << "\n";
    } else {
      int32_t ind;
      int64_t new_val;
      std::cin >> ind >> new_val;
      ind--;
      edge_weights[ind] = new_val;
      if (new_val == 1) {
        join(edges[ind].src, edges[ind].dst);
      }
    }
  }
  return 0;
}

```