#include<iostream>
#include<vector>
#define ll long long
#define int long long 
#pragma GCC diagnostic error "-std=c++11"
using namespace std;
const int mxn=200005;
struct vertex{
	int nxt,col;ll dist;
	vertex(){}
	vertex(int _x,int _c,int _d):nxt(_x),col(_c),dist(_d){}
};
struct query{
	int id,x,y,f;
	query(){}
	query(int _i,int _x,int _y,int _f):id(_i),x(_x),y(_y),f(_f){}
};
vector<vertex> g[mxn<<1];
int n,m;
ll ans[mxn],cnt[mxn],dis[mxn],dep[mxn];
vector<query> q[mxn];
int fa[mxn][22];
inline void predfs(int u,int par,ll dp){
	fa[u][0]=par;dep[u]=dp;
	for(vertex v:g[u]){
		if(v.nxt==par) continue;
		predfs(v.nxt,u,dp+1);
	}
}
inline void parinit(){
	for(int j=1;j<=19;++j) for(int i=1;i<=n;++i) fa[i][j]=fa[fa[i][j-1]][j-1];
}
inline int lca(int x,int y){
	if(dep[x]>dep[y]) swap(x,y);
	int step=dep[y]-dep[x],i;
	for(i=19;~i;--i) if(step&1<<i) y=fa[y][i];
	if(x==y) return x;
	for(i=19;~i;--i) if(fa[x][i]!=fa[y][i]) x=fa[x][i],y=fa[y][i];
	return fa[x][0];
}
inline void dfs(int u,int par,ll dist){
	int i;
	for(i=0;i<q[u].size();++i){
		int id=q[u][i].id,a=q[u][i].x,b=q[u][i].y,f=q[u][i].f;
		ans[id]+=1ll*f*(dist-dis[a]+cnt[a]*b);
	}
	for(vertex v:g[u]){
		int vv=v.nxt,c=v.col,ds=v.dist;
		if(vv==par) continue;
		++cnt[c],dis[c]+=ds;
		dfs(vv,u,dist+ds);
		--cnt[c],dis[c]-=ds;
	}
}
signed main(){
	ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
	cin>>n>>m;
	int i,j,x,y,col,len,u,v;
	for(i=1;i<n;++i){
		cin>>x>>y>>col>>len;
		g[x].push_back(vertex(y,col,len));
		g[y].push_back(vertex(x,col,len));
	}
	predfs(1,0,0);
	parinit();
	for(i=1;i<=m;++i){
		cin>>x>>y>>u>>v;
		q[u].push_back(query(i,x,y,1));
		q[v].push_back(query(i,x,y,1));
		int l=lca(u,v);
		q[l].push_back(query(i,x,y,-2));
	}
	dfs(1,0,0);
	for(i=1;i<=m;++i) cout<<ans[i]<<endl;
}
### Prompt

Your task is to create 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<iostream>
#include<vector>
#define ll long long
#define int long long 
#pragma GCC diagnostic error "-std=c++11"
using namespace std;
const int mxn=200005;
struct vertex{
	int nxt,col;ll dist;
	vertex(){}
	vertex(int _x,int _c,int _d):nxt(_x),col(_c),dist(_d){}
};
struct query{
	int id,x,y,f;
	query(){}
	query(int _i,int _x,int _y,int _f):id(_i),x(_x),y(_y),f(_f){}
};
vector<vertex> g[mxn<<1];
int n,m;
ll ans[mxn],cnt[mxn],dis[mxn],dep[mxn];
vector<query> q[mxn];
int fa[mxn][22];
inline void predfs(int u,int par,ll dp){
	fa[u][0]=par;dep[u]=dp;
	for(vertex v:g[u]){
		if(v.nxt==par) continue;
		predfs(v.nxt,u,dp+1);
	}
}
inline void parinit(){
	for(int j=1;j<=19;++j) for(int i=1;i<=n;++i) fa[i][j]=fa[fa[i][j-1]][j-1];
}
inline int lca(int x,int y){
	if(dep[x]>dep[y]) swap(x,y);
	int step=dep[y]-dep[x],i;
	for(i=19;~i;--i) if(step&1<<i) y=fa[y][i];
	if(x==y) return x;
	for(i=19;~i;--i) if(fa[x][i]!=fa[y][i]) x=fa[x][i],y=fa[y][i];
	return fa[x][0];
}
inline void dfs(int u,int par,ll dist){
	int i;
	for(i=0;i<q[u].size();++i){
		int id=q[u][i].id,a=q[u][i].x,b=q[u][i].y,f=q[u][i].f;
		ans[id]+=1ll*f*(dist-dis[a]+cnt[a]*b);
	}
	for(vertex v:g[u]){
		int vv=v.nxt,c=v.col,ds=v.dist;
		if(vv==par) continue;
		++cnt[c],dis[c]+=ds;
		dfs(vv,u,dist+ds);
		--cnt[c],dis[c]-=ds;
	}
}
signed main(){
	ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
	cin>>n>>m;
	int i,j,x,y,col,len,u,v;
	for(i=1;i<n;++i){
		cin>>x>>y>>col>>len;
		g[x].push_back(vertex(y,col,len));
		g[y].push_back(vertex(x,col,len));
	}
	predfs(1,0,0);
	parinit();
	for(i=1;i<=m;++i){
		cin>>x>>y>>u>>v;
		q[u].push_back(query(i,x,y,1));
		q[v].push_back(query(i,x,y,1));
		int l=lca(u,v);
		q[l].push_back(query(i,x,y,-2));
	}
	dfs(1,0,0);
	for(i=1;i<=m;++i) cout<<ans[i]<<endl;
}
```