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.

-----Sample 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

-----Sample Output-----
130
200
60

The graph in this input is as follows:

Here the edges of Color 1 are shown as solid red lines, the edge of Color 2 is shown as a bold green line, and the edge of Color 4 is shown as a blue dashed line.
 - Query 1: Assuming that the length of every edge whose color is 1 is changed to 100, the distance between Vertex 1 and Vertex 4 is 100 + 30 = 130.
 - Query 2: Assuming that the length of every edge whose color is 1 is changed to 100, the distance between Vertex 1 and Vertex 5 is 100 + 100 = 200.
 - Query 3: Assuming that the length of every edge whose color is 3 is changed to 1000 (there is no such edge), the distance between Vertex 3 and Vertex 4 is 20 + 10 + 30 = 60. Note that the edges of Color 1 now have their original lengths.

```python

USER_FILENAME = "<user_code>"
import sys, json, builtins
import math, heapq, bisect, itertools, functools, collections, statistics, fractions, decimal, operator, array, random, re, string, os, pathlib
try:
    import resource as _res
except Exception:
    _res = None
from collections import Counter, defaultdict, deque, OrderedDict
from functools import lru_cache, reduce
from itertools import accumulate, permutations, combinations, product
from math import gcd, ceil, floor, sqrt
from decimal import Decimal
try:
    from typing import *
except Exception:
    pass
try:
    sys.setrecursionlimit(1_000_000)
except Exception:
    pass
try:
    import site as _site
    try:
        _sys_sites = _site.getsitepackages() if hasattr(_site, "getsitepackages") else []
        for _p in _sys_sites:
            if _p and _p not in sys.path:
                sys.path.append(_p)
    except Exception:
        pass
    try:
        _usp = _site.getusersitepackages()
        if isinstance(_usp, str):
            _usp = [_usp]
        for _p in _usp:
            if _p and _p not in sys.path:
                sys.path.append(_p)
    except Exception:
        pass
except Exception:
    pass

ns = {"__name__": "__main__"}
for _k, _v in list(globals().items()):
    if not _k.startswith("_"):
        ns[_k] = _v
_CODE = 'import sys\ninput = sys.stdin.readline\nsys.setrecursionlimit(10**8)\n\n\nclass SegmentTree1():\n    """\n    1-indexed Segment Tree\n    """\n    def __init__(self, n_, ele_id, operation_func):\n        self.n = 1 << (n_ - 1).bit_length()  # size\n        self.data = [ele_id] * (2 * self.n)  # binary tree\n        self.ele_id = ele_id  # identity element\n        self.operation_func = operation_func  # binary operation of monoid\n\n    def __getitem__(self, idx):\n        return self.data[idx + self.n]\n\n    def build(self, data_init):\n        for i in range(len(data_init)):\n            self.data[i + self.n] = data_init[i]\n        for i in range(self.n - 1, 0, -1):\n            self.data[i] = self.operation_func(self.data[2 * i],\n                                               self.data[2 * i + 1])\n\n    def update(self, idx, x):\n        # change idx-th element to x (idx : 0-indexed)\n        idx += self.n\n        self.data[idx] = x\n        while idx > 1:\n            idx = idx >> 1\n            self.data[idx] = self.operation_func(self.data[2 * idx],\n                                                 self.data[2 * idx + 1])\n\n    def query(self, l, r):\n        # query for interval [l, r) (l, r : 0-indexed)\n        l += self.n\n        r += self.n\n        ret = self.ele_id\n        while l < r:\n            if l & 1:  # right child\n                ret = self.operation_func(ret, self.data[l])\n                l += 1\n            if r & 1:  # right child\n                r -= 1\n                ret = self.operation_func(ret, self.data[r])\n            # go to parent-nodes\n            l = l >> 1\n            r = r >> 1\n        return ret\n\n\nclass Tree():\n    def __init__(self, n, graph, v_root):\n        self.n = n  # number of nodes\n        self.graph = graph  # adjacent list of graph\n        self.v_root = v_root  # root node\n\n        # euler tour\n        self.first_idx = [2 * self.n] * self.n\n        self.euler_tour = []\n        self.euler_depth_topo = []\n        self.euler_depth_real = []\n        self.euler_tour_dfs(self.v_root, -1, 0, 0)\n\n        depth_list = [(di, i) for i, di in enumerate(self.euler_depth_topo)]\n        INF = (2 * self.n, -1)\n        operation_func = lambda a, b: a if a[0] < b[0] else b\n        self.st_rmq = SegmentTree1(2 * self.n - 1, INF, operation_func)\n        self.st_rmq.build(depth_list)\n\n    def euler_tour_dfs(self, v, v_par, depth_topo, depth_real):\n        self.first_idx[v] = len(self.euler_tour)\n        self.euler_tour.append(v)\n        self.euler_depth_topo.append(depth_topo)\n        self.euler_depth_real.append(depth_real)\n        for v_next, c, d in self.graph[v]:\n            if v_next == v_par:\n                continue\n            self.euler_tour_dfs(v_next, v, depth_topo + 1, depth_real + d)\n            self.euler_tour.append(v)\n            self.euler_depth_topo.append(depth_topo)\n            self.euler_depth_real.append(depth_real)\n\n    def depth_topo(self, v):\n        return self.euler_depth_topo[self.first_idx[v]]\n\n    def depth_real(self, v):\n        return self.euler_depth_real[self.first_idx[v]]\n\n    def lca(self, u, v):\n        u_idx, v_idx = self.first_idx[u], self.first_idx[v]\n        if u_idx > v_idx:\n            u_idx, v_idx = v_idx, u_idx\n        _, idx = self.st_rmq.query(u_idx, v_idx + 1)\n        return self.euler_tour[idx]\n\n    def dist(self, u, v):\n        lca_uv = self.lca(u, v)\n        return self.depth(u) + self.depth(v) - 2 * self.depth(lca_uv)\n\n\nn, q = list(map(int, input().split()))\ngraph = [[] for _ in range(n)]\nfor _ in range(n - 1):\n    a, b, c, d = list(map(int, input().split()))\n    a -= 1\n    b -= 1\n    graph[a].append((b, c, d))\n    graph[b].append((a, c, d))\n\ntree = Tree(n, graph, 0)\n\nquery = []\nmemo = [set() for i in range(n)]\nfor _ in range(q):\n    x, y, u, v = list(map(int, input().split()))\n    u -= 1\n    v -= 1\n    lca_uv = tree.lca(u, v)\n    memo[u].add(x)\n    memo[v].add(x)\n    memo[lca_uv].add(x)\n\n    query.append((x, y, u, v, lca_uv))\n\nn_color = [0] * n\nd_color = [0] * n\nn_color_memo = {}\nd_color_memo = {}\n\n\ndef dfs(v, v_par, depth):\n    for c in memo[v]:\n        n_color_memo[(v, c)] = n_color[c]\n        d_color_memo[(v, c)] = d_color[c]\n\n    for v_next, c, d in graph[v]:\n        if v_next == v_par:\n            continue\n        n_color[c] += 1\n        d_color[c] += d\n        dfs(v_next, v, depth + d)\n        n_color[c] -= 1\n        d_color[c] -= d\n\n\ndfs(0, -1, 0)\n\nfor x, y, u, v, lca in query:\n    depth_u = tree.depth_real(u)\n    depth_u += -d_color_memo[(u, x)] + y * n_color_memo[(u, x)]\n    depth_v = tree.depth_real(v)\n    depth_v += -d_color_memo[(v, x)] + y * n_color_memo[(v, x)]\n    depth_lca = tree.depth_real(lca)\n    depth_lca += -d_color_memo[(lca, x)] + y * n_color_memo[(lca, x)]\n\n    ans = depth_u + depth_v - 2 * depth_lca\n    print(ans)\n'
_co = compile(_CODE, USER_FILENAME, "exec")
exec(_co, ns, ns)

```

Measured memory_bytes: 22706