#include <bits/stdc++.h>
using namespace std;
const double EPS = 1e-10;
const long long INF = 1e18;
const int N = 3e5 + 1000;
const int M = 1e5 + 10;
struct node {
  int v, c;
};
struct segtree {
  int l, r, a, b;
  long long w, c;
} f[N * 2];
int n, m, tim, t;
vector<node> g[N];
int dep[N], p[N][20], l[N], r[N], idn[N], a[N], c[N], pre[N], idt[N];
long long val[N * 2], dis[N];
void push_down(int p) {
  if (f[p].c == 0) return;
  f[f[p].l].w += f[p].c;
  f[f[p].r].w += f[p].c;
  f[f[p].l].c += f[p].c;
  f[f[p].r].c += f[p].c;
  f[p].c = 0;
  return;
}
void build(int p, int a, int b) {
  f[p].a = a;
  f[p].b = b;
  f[p].c = 0;
  if (a + 1 == b) {
    f[p].w = dis[pre[a]] + c[pre[a]];
    return;
  }
  int m = (a + b) / 2;
  t++;
  f[p].l = t;
  build(t, a, m);
  t++;
  f[p].r = t;
  build(t, m, b);
  f[p].w = min(f[f[p].l].w, f[f[p].r].w);
  return;
}
void Insert(int p, int x, int y, int z) {
  if (x <= f[p].a && y >= f[p].b - 1) {
    f[p].w += z;
    f[p].c += z;
    return;
  }
  push_down(p);
  int m = (f[p].a + f[p].b) / 2;
  if (x < m) Insert(f[p].l, x, y, z);
  if (y >= m) Insert(f[p].r, x, y, z);
  f[p].w = min(f[f[p].l].w, f[f[p].r].w);
  return;
}
long long Query(int p, int x, int y) {
  if (x == 0) return 0;
  long long ans = INF;
  if (x <= f[p].a && y >= f[p].b - 1) {
    return f[p].w;
  }
  push_down(p);
  int m = (f[p].a + f[p].b) / 2;
  if (x < m) ans = min(ans, Query(f[p].l, x, y));
  if (y >= m) ans = min(ans, Query(f[p].r, x, y));
  return ans;
}
void dfs(int u, int fa) {
  p[u][0] = fa;
  for (int i = 1; i < 20; i++) p[u][i] = p[p[u][i - 1]][i - 1];
  for (int i = 0; i < g[u].size(); i++) {
    node &e = g[u][i];
    if (e.v == fa) continue;
    dis[e.v] = dis[u] + val[e.c];
    dep[e.v] = dep[u] + 1;
    l[e.c] = idn[e.v] = ++tim;
    pre[tim] = e.v;
    dfs(e.v, u);
    r[e.c] = idt[e.v] = tim;
  }
  return;
}
int lca(int x, int y) {
  if (dep[x] < dep[y]) swap(x, y);
  for (int i = 19; i > -1; i--)
    if (dep[p[x][i]] >= dep[y]) x = p[x][i];
  if (x == y) return x;
  for (int i = 19; i > -1; i--)
    if (p[x][i] != p[y][i]) {
      x = p[x][i];
      y = p[y][i];
    }
  return p[x][0];
}
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i < n; i++) {
    int x, y, z;
    scanf("%d%d%d", &x, &y, &z);
    node e;
    e.v = y;
    e.c = i;
    g[x].push_back(e);
    val[i] = z;
  }
  tim = 0;
  dep[1] = 1;
  dfs(1, 0);
  for (int i = 1; i < n; i++) {
    int x, y, z;
    scanf("%d%d%d", &x, &y, &z);
    c[x] = z;
    a[i] = x;
  }
  c[1] = idn[1] = idt[1] = 0;
  t = 1;
  build(1, 1, n);
  while (m--) {
    int op, x, y;
    scanf("%d", &op);
    if (op == 1) {
      int k;
      scanf("%d%d", &x, &y);
      if (x < n) {
        Insert(1, l[x], r[x], y - val[x]);
        val[x] = y;
      } else {
        k = a[x - n + 1];
        Insert(1, idn[k], idn[k], y - c[k]);
        c[k] = y;
      }
    } else {
      scanf("%d%d", &x, &y);
      int k = lca(x, y);
      long long ans;
      if (k == x) {
        ans = Query(1, idn[y], idn[y]) - Query(1, idn[x], idn[x]) + c[x] - c[y];
      } else {
        ans = Query(1, idn[x], idt[x]);
        long long dx = Query(1, idn[x], idn[x]) - c[x];
        long long dy = Query(1, idn[y], idn[y]) - c[y];
        ans = ans - dx + dy;
      }
      printf("%I64d\n", ans);
    }
  }
  return 0;
}

### Prompt

Please formulate a cpp solution to the following 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

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const double EPS = 1e-10;
const long long INF = 1e18;
const int N = 3e5 + 1000;
const int M = 1e5 + 10;
struct node {
  int v, c;
};
struct segtree {
  int l, r, a, b;
  long long w, c;
} f[N * 2];
int n, m, tim, t;
vector<node> g[N];
int dep[N], p[N][20], l[N], r[N], idn[N], a[N], c[N], pre[N], idt[N];
long long val[N * 2], dis[N];
void push_down(int p) {
  if (f[p].c == 0) return;
  f[f[p].l].w += f[p].c;
  f[f[p].r].w += f[p].c;
  f[f[p].l].c += f[p].c;
  f[f[p].r].c += f[p].c;
  f[p].c = 0;
  return;
}
void build(int p, int a, int b) {
  f[p].a = a;
  f[p].b = b;
  f[p].c = 0;
  if (a + 1 == b) {
    f[p].w = dis[pre[a]] + c[pre[a]];
    return;
  }
  int m = (a + b) / 2;
  t++;
  f[p].l = t;
  build(t, a, m);
  t++;
  f[p].r = t;
  build(t, m, b);
  f[p].w = min(f[f[p].l].w, f[f[p].r].w);
  return;
}
void Insert(int p, int x, int y, int z) {
  if (x <= f[p].a && y >= f[p].b - 1) {
    f[p].w += z;
    f[p].c += z;
    return;
  }
  push_down(p);
  int m = (f[p].a + f[p].b) / 2;
  if (x < m) Insert(f[p].l, x, y, z);
  if (y >= m) Insert(f[p].r, x, y, z);
  f[p].w = min(f[f[p].l].w, f[f[p].r].w);
  return;
}
long long Query(int p, int x, int y) {
  if (x == 0) return 0;
  long long ans = INF;
  if (x <= f[p].a && y >= f[p].b - 1) {
    return f[p].w;
  }
  push_down(p);
  int m = (f[p].a + f[p].b) / 2;
  if (x < m) ans = min(ans, Query(f[p].l, x, y));
  if (y >= m) ans = min(ans, Query(f[p].r, x, y));
  return ans;
}
void dfs(int u, int fa) {
  p[u][0] = fa;
  for (int i = 1; i < 20; i++) p[u][i] = p[p[u][i - 1]][i - 1];
  for (int i = 0; i < g[u].size(); i++) {
    node &e = g[u][i];
    if (e.v == fa) continue;
    dis[e.v] = dis[u] + val[e.c];
    dep[e.v] = dep[u] + 1;
    l[e.c] = idn[e.v] = ++tim;
    pre[tim] = e.v;
    dfs(e.v, u);
    r[e.c] = idt[e.v] = tim;
  }
  return;
}
int lca(int x, int y) {
  if (dep[x] < dep[y]) swap(x, y);
  for (int i = 19; i > -1; i--)
    if (dep[p[x][i]] >= dep[y]) x = p[x][i];
  if (x == y) return x;
  for (int i = 19; i > -1; i--)
    if (p[x][i] != p[y][i]) {
      x = p[x][i];
      y = p[y][i];
    }
  return p[x][0];
}
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i < n; i++) {
    int x, y, z;
    scanf("%d%d%d", &x, &y, &z);
    node e;
    e.v = y;
    e.c = i;
    g[x].push_back(e);
    val[i] = z;
  }
  tim = 0;
  dep[1] = 1;
  dfs(1, 0);
  for (int i = 1; i < n; i++) {
    int x, y, z;
    scanf("%d%d%d", &x, &y, &z);
    c[x] = z;
    a[i] = x;
  }
  c[1] = idn[1] = idt[1] = 0;
  t = 1;
  build(1, 1, n);
  while (m--) {
    int op, x, y;
    scanf("%d", &op);
    if (op == 1) {
      int k;
      scanf("%d%d", &x, &y);
      if (x < n) {
        Insert(1, l[x], r[x], y - val[x]);
        val[x] = y;
      } else {
        k = a[x - n + 1];
        Insert(1, idn[k], idn[k], y - c[k]);
        c[k] = y;
      }
    } else {
      scanf("%d%d", &x, &y);
      int k = lca(x, y);
      long long ans;
      if (k == x) {
        ans = Query(1, idn[y], idn[y]) - Query(1, idn[x], idn[x]) + c[x] - c[y];
      } else {
        ans = Query(1, idn[x], idt[x]);
        long long dx = Query(1, idn[x], idn[x]) - c[x];
        long long dy = Query(1, idn[y], idn[y]) - c[y];
        ans = ans - dx + dy;
      }
      printf("%I64d\n", ans);
    }
  }
  return 0;
}

```