Problem: You are given a directed weighted graph with n nodes and 2n - 2 edges. The nodes are labeled from 1 to n, while the edges are labeled from 1 to 2n - 2. The graph's edges can be split into two parts.

  * The first n - 1 edges will form a rooted spanning tree, with node 1 as the root. All these edges will point away from the root. 
  * The last n - 1 edges will be from node i to node 1, for all 2 ≤ i ≤ n. 



You are given q queries. There are two types of queries

  * 1 i w: Change the weight of the i-th edge to w
  * 2 u v: Print the length of the shortest path between nodes u to v



Given these queries, print the shortest path lengths.

Input

The first line of input will contain two integers n, q (2 ≤ n, q ≤ 200 000), the number of nodes, and the number of queries, respectively.

The next 2n - 2 integers will contain 3 integers ai, bi, ci, denoting a directed edge from node ai to node bi with weight ci.

The first n - 1 of these lines will describe a rooted spanning tree pointing away from node 1, while the last n - 1 of these lines will have bi = 1.

More specifically, 

  * The edges (a1, b1), (a2, b2), ... (an - 1, bn - 1) will describe a rooted spanning tree pointing away from node 1. 
  * bj = 1 for n ≤ j ≤ 2n - 2. 
  * an, an + 1, ..., a2n - 2 will be distinct and between 2 and n. 



The next q lines will contain 3 integers, describing a query in the format described in the statement.

All edge weights will be between 1 and 106.

Output

For each type 2 query, print the length of the shortest path in its own line.

Example

Input

5 9
1 3 1
3 2 2
1 4 3
3 5 4
5 1 5
3 1 6
2 1 7
4 1 8
2 1 1
2 1 3
2 3 5
2 5 2
1 1 100
2 1 3
1 8 30
2 4 2
2 2 4


Output

0
1
4
8
100
132
10

Solution (in CPP):

Solution:
#include <bits/stdc++.h>
using namespace std;
const int MaxN = 200003;
int n, q;
struct Edge {
  int u, v, w;
} edge[MaxN * 2];
vector<pair<int, int> > e[MaxN];
int fa[MaxN], dep[MaxN], sz[MaxN], id[MaxN], idx;
long long dist[MaxN], weight[MaxN];
void dfs(int x) {
  id[x] = ++idx;
  for (pair<int, int>& i : e[x]) {
    int v = i.first, w = i.second;
    dfs(v);
  }
}
void dfs2(int x) {
  sz[id[x]] = 1;
  for (pair<int, int>& i : e[x]) {
    int v = i.first, w = i.second;
    dist[id[v]] = dist[id[x]] + w;
    dfs2(v);
    sz[id[x]] += sz[id[v]];
  }
}
namespace MinSegTree {
long long mn[MaxN << 2], adds[MaxN << 2];
void build(int p, int l, int r) {
  if (l == r) {
    mn[p] = dist[l] + weight[l];
    adds[p] = 0;
    return;
  }
  int mid = (l + r) / 2;
  build(p * 2, l, mid);
  build(p * 2 + 1, mid + 1, r);
  mn[p] = min(mn[p * 2], mn[p * 2 + 1]);
  adds[p] = 0;
}
inline void init() { build(1, 1, n); }
inline void pushdown(int p, int l, int r) {
  mn[p] += adds[p];
  if (l < r) {
    adds[p * 2] += adds[p];
    adds[p * 2 + 1] += adds[p];
  }
  adds[p] = 0;
}
inline void update(int p, int l, int r) {
  pushdown(p, l, r);
  if (l < r) {
    mn[p] = min(mn[p * 2] + adds[p * 2], mn[p * 2 + 1] + adds[p * 2 + 1]);
  }
}
void add(long long s, int p, int l, int r, int ll, int rr) {
  if (ll <= l && r <= rr) {
    adds[p] += s;
    return;
  }
  pushdown(p, l, r);
  int mid = (l + r) / 2;
  if (ll <= mid) add(s, p * 2, l, mid, ll, rr);
  if (rr > mid) add(s, p * 2 + 1, mid + 1, r, ll, rr);
  update(p, l, r);
}
long long query(int p, int l, int r, int ll, int rr) {
  if (ll <= l && r <= rr) {
    return mn[p] + adds[p];
  }
  pushdown(p, l, r);
  long long ret = 0x7f7f7f7f7f7f7f7fLL;
  int mid = (l + r) / 2;
  if (ll <= mid) ret = min(ret, query(p * 2, l, mid, ll, rr));
  if (rr > mid) ret = min(ret, query(p * 2 + 1, mid + 1, r, ll, rr));
  return ret;
}
}  // namespace MinSegTree
namespace DistSegTree {
long long s[MaxN << 2];
void build(int p, int l, int r) {
  if (l == r) {
    s[p] = dist[l];
    return;
  }
  int mid = (l + r) / 2;
  build(p * 2, l, mid);
  build(p * 2 + 1, mid + 1, r);
}
inline void init() { build(1, 1, n); }
inline void pushdown(int p) {
  s[p * 2] += s[p];
  s[p * 2 + 1] += s[p];
  s[p] = 0;
}
void add(int x, int p, int l, int r, int ll, int rr) {
  if (ll <= l && r <= rr) {
    s[p] += x;
    return;
  }
  pushdown(p);
  int mid = (l + r) / 2;
  if (ll <= mid) add(x, p * 2, l, mid, ll, rr);
  if (rr > mid) add(x, p * 2 + 1, mid + 1, r, ll, rr);
}
inline long long query(int x, int p, int l, int r) {
  if (l == r) return s[p];
  pushdown(p);
  int mid = (l + r) / 2;
  if (x <= mid)
    return query(x, p * 2, l, mid);
  else
    return query(x, p * 2 + 1, mid + 1, r);
}
}  // namespace DistSegTree
int main() {
  scanf("%d%d", &n, &q);
  for (int i = 1; i < n; ++i) {
    int u, v, w;
    scanf("%d%d%d", &u, &v, &w);
    edge[i].u = u, edge[i].v = v, edge[i].w = w;
    e[u].emplace_back(v, w);
  }
  fa[1] = 1, dep[1] = 0, dist[1] = 0, weight[1] = 0;
  dfs(1);
  dfs2(1);
  for (int i = n; i <= 2 * n - 2; ++i) {
    int u, v, w;
    scanf("%d%d%d", &u, &v, &w);
    edge[i].u = u, edge[i].v = v, edge[i].w = w;
    weight[id[u]] = w;
  }
  MinSegTree::init();
  DistSegTree::init();
  for (int i = 1; i <= q; ++i) {
    int type;
    scanf("%d", &type);
    if (type == 1) {
      int pos, x;
      scanf("%d%d", &pos, &x);
      if (pos < n) {
        int change = x - edge[pos].w;
        int l = id[edge[pos].v], r = l + sz[l] - 1;
        MinSegTree::add(change, 1, 1, n, l, r);
        DistSegTree::add(change, 1, 1, n, l, r);
        edge[pos].w = x;
      } else {
        int change = x - edge[pos].w;
        int l = id[edge[pos].u], r = l + sz[l] - 1;
        MinSegTree::add(change, 1, 1, n, l, l);
        edge[pos].w = x;
      }
    } else {
      int u, v;
      scanf("%d%d", &u, &v);
      int l = id[u], r = l + sz[l] - 1;
      long long ans;
      if (l <= id[v] && id[v] <= r) {
        ans = DistSegTree::query(id[v], 1, 1, n) -
              DistSegTree::query(id[u], 1, 1, n);
      } else {
        ans = MinSegTree::query(1, 1, n, l, r) -
              DistSegTree::query(id[u], 1, 1, n) +
              DistSegTree::query(id[v], 1, 1, n);
      }
      printf("%lld\n", ans);
    }
  }
  return 0;
}