#include <bits/stdc++.h>

#define rep(i,n) for(int i=0;i<n;i++)
#define repn(i,n) for(int i=1;i<=n;i++)
#define LL long long
#define pii pair <int,int>
#define fi first
#define se second
#define pb push_back
#define mpr make_pair

using namespace std;

const LL MOD=1e9+7;

int n,q,x,y,c,d,depth[100010],num[100010],sum[100010],ans[100010];
int par[20][100010];
vector <int> g[100010];
vector <pair <pii,int> > g2[100010];
vector <pair <pii,pii> > v[100010];

void dfs(int pos,int no,int d)
{
	depth[pos]=d;
	par[0][pos]=no;
	rep(i,g[pos].size()) if(g[pos][i]!=no) dfs(g[pos][i],pos,d+1);
}

int lca(int pos1,int pos2)
{
	if(depth[pos1]<depth[pos2]) swap(pos1,pos2);
	for(int i=18;i>=0;i--) if(depth[pos1]-(int)pow(2,i)>=depth[pos2]) pos1=par[i][pos1];
	for(int i=18;i>=0;i--)
	{
		if(par[i][pos1]!=par[i][pos2])
		{
			pos1=par[i][pos1];
			pos2=par[i][pos2];
		}
	}
	if(pos1==pos2) return pos1;
	return par[0][pos1];
}

void dfs2(int pos,int no,int d)
{
	rep(i,v[pos].size())
	{
		if(v[pos][i].fi.se==1) ans[v[pos][i].fi.fi]+=d-sum[v[pos][i].se.fi]+num[v[pos][i].se.fi]*v[pos][i].se.se;
		else ans[v[pos][i].fi.fi]-=(d-sum[v[pos][i].se.fi]+num[v[pos][i].se.fi]*v[pos][i].se.se)*2;
	}
	rep(i,g2[pos].size())
	{
		if(g2[pos][i].fi.fi==no) continue;
		num[g2[pos][i].fi.se]++;
		sum[g2[pos][i].fi.se]+=g2[pos][i].se;
		dfs2(g2[pos][i].fi.fi,pos,d+g2[pos][i].se);
		num[g2[pos][i].fi.se]--;
		sum[g2[pos][i].fi.se]-=g2[pos][i].se;
	}
}

int main()
{
	cin>>n>>q;
	rep(i,n-1)
	{
		scanf("%d%d%d%d",&x,&y,&c,&d);
		g[x].pb(y);
		g[y].pb(x);
		g2[x].pb(mpr(mpr(y,c),d));
		g2[y].pb(mpr(mpr(x,c),d));
	}
	rep(i,20) rep(j,100005) par[i][j]=-1;
	dfs(1,-1,0);
	rep(i,18)
	{
		repn(j,n)
		{
			if(par[i][j]==-1) continue;
			par[i+1][j]=par[i][par[i][j]];
		}
	}
	rep(qn,q)
	{
		scanf("%d%d%d%d",&c,&d,&x,&y);
		int z=lca(x,y);
		v[x].pb(mpr(mpr(qn,1),mpr(c,d)));
		v[y].pb(mpr(mpr(qn,1),mpr(c,d)));
		v[z].pb(mpr(mpr(qn,-1),mpr(c,d)));
	}
	dfs2(1,0,0);
	rep(i,q) cout<<ans[i]<<endl;
	return 0;
}
### Prompt

Your challenge is to write a CPP solution to 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>

#define rep(i,n) for(int i=0;i<n;i++)
#define repn(i,n) for(int i=1;i<=n;i++)
#define LL long long
#define pii pair <int,int>
#define fi first
#define se second
#define pb push_back
#define mpr make_pair

using namespace std;

const LL MOD=1e9+7;

int n,q,x,y,c,d,depth[100010],num[100010],sum[100010],ans[100010];
int par[20][100010];
vector <int> g[100010];
vector <pair <pii,int> > g2[100010];
vector <pair <pii,pii> > v[100010];

void dfs(int pos,int no,int d)
{
	depth[pos]=d;
	par[0][pos]=no;
	rep(i,g[pos].size()) if(g[pos][i]!=no) dfs(g[pos][i],pos,d+1);
}

int lca(int pos1,int pos2)
{
	if(depth[pos1]<depth[pos2]) swap(pos1,pos2);
	for(int i=18;i>=0;i--) if(depth[pos1]-(int)pow(2,i)>=depth[pos2]) pos1=par[i][pos1];
	for(int i=18;i>=0;i--)
	{
		if(par[i][pos1]!=par[i][pos2])
		{
			pos1=par[i][pos1];
			pos2=par[i][pos2];
		}
	}
	if(pos1==pos2) return pos1;
	return par[0][pos1];
}

void dfs2(int pos,int no,int d)
{
	rep(i,v[pos].size())
	{
		if(v[pos][i].fi.se==1) ans[v[pos][i].fi.fi]+=d-sum[v[pos][i].se.fi]+num[v[pos][i].se.fi]*v[pos][i].se.se;
		else ans[v[pos][i].fi.fi]-=(d-sum[v[pos][i].se.fi]+num[v[pos][i].se.fi]*v[pos][i].se.se)*2;
	}
	rep(i,g2[pos].size())
	{
		if(g2[pos][i].fi.fi==no) continue;
		num[g2[pos][i].fi.se]++;
		sum[g2[pos][i].fi.se]+=g2[pos][i].se;
		dfs2(g2[pos][i].fi.fi,pos,d+g2[pos][i].se);
		num[g2[pos][i].fi.se]--;
		sum[g2[pos][i].fi.se]-=g2[pos][i].se;
	}
}

int main()
{
	cin>>n>>q;
	rep(i,n-1)
	{
		scanf("%d%d%d%d",&x,&y,&c,&d);
		g[x].pb(y);
		g[y].pb(x);
		g2[x].pb(mpr(mpr(y,c),d));
		g2[y].pb(mpr(mpr(x,c),d));
	}
	rep(i,20) rep(j,100005) par[i][j]=-1;
	dfs(1,-1,0);
	rep(i,18)
	{
		repn(j,n)
		{
			if(par[i][j]==-1) continue;
			par[i+1][j]=par[i][par[i][j]];
		}
	}
	rep(qn,q)
	{
		scanf("%d%d%d%d",&c,&d,&x,&y);
		int z=lca(x,y);
		v[x].pb(mpr(mpr(qn,1),mpr(c,d)));
		v[y].pb(mpr(mpr(qn,1),mpr(c,d)));
		v[z].pb(mpr(mpr(qn,-1),mpr(c,d)));
	}
	dfs2(1,0,0);
	rep(i,q) cout<<ans[i]<<endl;
	return 0;
}
```