#include <bits/stdc++.h>

using namespace std;

#define REP(i, a, n) for (int i = a, _n = n; i <= _n; ++i)
#define DREP(i, a, n) for (int i = a, _n = n; i >= _n; --i)
#define FOR(i, a, n) for (int i = a, _n = n; i < _n; ++i)
#define EREP(i, a) for (int i = first[a]; i; i = edge[i].nxt)
#define debug(x) cout << #x << " = " << x << endl

const int SIZE = 100005;

int n, q;

int first[SIZE], ecnt;
struct Edge {
  int v, d, c, nxt;
} edge[SIZE << 1];
void Add_Edge (int u, int v, int c, int d) {
  ++ecnt;
  edge[ecnt].v = v;
  edge[ecnt].c = c;
  edge[ecnt].d = d;
  edge[ecnt].nxt = first[u];
  first[u] = ecnt;
}

struct Query {
  int x, y, k;
  int id;
};
vector<Query> V[SIZE];

int dep[SIZE], dp[SIZE][17];

void dfs (int u) {
  EREP (i, u) {
    Edge& e = edge[i];
    if (e.v == dp[u][0]) continue;
    dep[e.v] = dep[u] + 1;
    dp[e.v][0] = u;
    dfs (e.v);
  }
}

int ans[SIZE], cnt[SIZE], sum[SIZE];

void Up (int& u, int step) {
  REP (i, 0, 16) if (1 << i & step)
    u = dp[u][i];
}

int LCA (int u, int v) {
  if (dep[u] < dep[v]) swap(u, v);
  Up (u, dep[u] - dep[v]);
  if (u == v) return u;
  DREP (i, 16, 0) if (dp[u][i] != dp[v][i])
    u = dp[u][i], v = dp[v][i];
  return dp[u][0];
}
int dis;

void DFS (int u) {
  FOR (i, 0, V[u].size()) {
    Query& q = V[u][i];
    ans[q.id] += (dis - sum[q.x] + cnt[q.x] * q.y) * q.k;
  }
  EREP (i, u) {
    Edge& e = edge[i];
    if (e.v == dp[u][0]) continue;
    dis += e.d;
    sum[e.c] += e.d;
    ++cnt[e.c];
    DFS (e.v);
    dis -= e.d;
    sum[e.c] -= e.d;
    --cnt[e.c];
  }
}

int main () {
  scanf ("%d%d", &n, &q);

  FOR (i, 1, n) {
    int u, v, c, d;
    scanf ("%d%d%d%d", &u, &v, &c, &d);
    Add_Edge (u, v, c, d);
    Add_Edge (v, u, c, d);
  }

  dfs (1);
  REP(i, 1, 16) REP (j, 1, n)
    dp[j][i] = dp[dp[j][i - 1]][i - 1];

  REP (i, 1, q) {
    int x, y, u, v;
    scanf ("%d%d%d%d", &x, &y, &u, &v);
    int lca = LCA (u, v);
    V[u].push_back((Query) <% x, y, 1, i%>);
    V[v].push_back((Query) <% x, y, 1, i%>);
    V[lca].push_back((Query) <% x, y, -2, i%>);
  }
  DFS (1);

  REP (i, 1, q) printf ("%d\n", ans[i]);
  return 0;
}

### Prompt

In CPP, your task is to solve the following problem:

There is a tree with N vertices numbered 1 to N. The i-th edge in this tree connects Vertex a_i and Vertex b_i, and the color and length of that edge are c_i and d_i, respectively. Here the color of each edge is represented by an integer between 1 and N-1 (inclusive). The same integer corresponds to the same color, and different integers correspond to different colors.

Answer the following Q queries:

* Query j (1 \leq j \leq Q): assuming that the length of every edge whose color is x_j is changed to y_j, find the distance between Vertex u_j and Vertex v_j. (The changes of the lengths of edges do not affect the subsequent queries.)

Constraints

* 2 \leq N \leq 10^5
* 1 \leq Q \leq 10^5
* 1 \leq a_i, b_i \leq N
* 1 \leq c_i \leq N-1
* 1 \leq d_i \leq 10^4
* 1 \leq x_j \leq N-1
* 1 \leq y_j \leq 10^4
* 1 \leq u_j < v_j \leq N
* The given graph is a tree.
* All values in input are integers.

Input

Input is given from Standard Input in the following format:


N Q
a_1 b_1 c_1 d_1
:
a_{N-1} b_{N-1} c_{N-1} d_{N-1}
x_1 y_1 u_1 v_1
:
x_Q y_Q u_Q v_Q


Output

Print Q lines. The j-th line (1 \leq j \leq Q) should contain the answer to Query j.

Example

Input

5 3
1 2 1 10
1 3 2 20
2 4 4 30
5 2 1 40
1 100 1 4
1 100 1 5
3 1000 3 4


Output

130
200
60

### Response

```cpp
#include <bits/stdc++.h>

using namespace std;

#define REP(i, a, n) for (int i = a, _n = n; i <= _n; ++i)
#define DREP(i, a, n) for (int i = a, _n = n; i >= _n; --i)
#define FOR(i, a, n) for (int i = a, _n = n; i < _n; ++i)
#define EREP(i, a) for (int i = first[a]; i; i = edge[i].nxt)
#define debug(x) cout << #x << " = " << x << endl

const int SIZE = 100005;

int n, q;

int first[SIZE], ecnt;
struct Edge {
  int v, d, c, nxt;
} edge[SIZE << 1];
void Add_Edge (int u, int v, int c, int d) {
  ++ecnt;
  edge[ecnt].v = v;
  edge[ecnt].c = c;
  edge[ecnt].d = d;
  edge[ecnt].nxt = first[u];
  first[u] = ecnt;
}

struct Query {
  int x, y, k;
  int id;
};
vector<Query> V[SIZE];

int dep[SIZE], dp[SIZE][17];

void dfs (int u) {
  EREP (i, u) {
    Edge& e = edge[i];
    if (e.v == dp[u][0]) continue;
    dep[e.v] = dep[u] + 1;
    dp[e.v][0] = u;
    dfs (e.v);
  }
}

int ans[SIZE], cnt[SIZE], sum[SIZE];

void Up (int& u, int step) {
  REP (i, 0, 16) if (1 << i & step)
    u = dp[u][i];
}

int LCA (int u, int v) {
  if (dep[u] < dep[v]) swap(u, v);
  Up (u, dep[u] - dep[v]);
  if (u == v) return u;
  DREP (i, 16, 0) if (dp[u][i] != dp[v][i])
    u = dp[u][i], v = dp[v][i];
  return dp[u][0];
}
int dis;

void DFS (int u) {
  FOR (i, 0, V[u].size()) {
    Query& q = V[u][i];
    ans[q.id] += (dis - sum[q.x] + cnt[q.x] * q.y) * q.k;
  }
  EREP (i, u) {
    Edge& e = edge[i];
    if (e.v == dp[u][0]) continue;
    dis += e.d;
    sum[e.c] += e.d;
    ++cnt[e.c];
    DFS (e.v);
    dis -= e.d;
    sum[e.c] -= e.d;
    --cnt[e.c];
  }
}

int main () {
  scanf ("%d%d", &n, &q);

  FOR (i, 1, n) {
    int u, v, c, d;
    scanf ("%d%d%d%d", &u, &v, &c, &d);
    Add_Edge (u, v, c, d);
    Add_Edge (v, u, c, d);
  }

  dfs (1);
  REP(i, 1, 16) REP (j, 1, n)
    dp[j][i] = dp[dp[j][i - 1]][i - 1];

  REP (i, 1, q) {
    int x, y, u, v;
    scanf ("%d%d%d%d", &x, &y, &u, &v);
    int lca = LCA (u, v);
    V[u].push_back((Query) <% x, y, 1, i%>);
    V[v].push_back((Query) <% x, y, 1, i%>);
    V[lca].push_back((Query) <% x, y, -2, i%>);
  }
  DFS (1);

  REP (i, 1, q) printf ("%d\n", ans[i]);
  return 0;
}

```