#include<bits/stdc++.h>
#define FOR(i,x,y) for(int i=(x),i##END=(y);i<=i##END;++i)
#define DOR(i,x,y) for(int i=(x),i##END=(y);i>=i##END;--i)
template<typename T,typename _T>inline bool chk_min(T &x,const _T y){return y<x?x=y,1:0;}
template<typename T,typename _T>inline bool chk_max(T &x,const _T y){return x<y?x=y,1:0;}
typedef long long ll;
const int P=1e9+7;
const int N=100005;
template<const int maxn,const int maxm,typename T>struct LinkedList
{
	int head[maxn],nxt[maxm],tot;T to[maxm];
	LinkedList(){clear();}
	T &operator [](const int x){return to[x];}
	void clear(){memset(head,-1,sizeof(head)),tot=0;}
	void add(int u,T v){to[++tot]=v,nxt[tot]=head[u],head[u]=tot;}
	#define EOR(i,G,u) for(int i=G.head[u];~i;i=G.nxt[i])
};
struct edge{int to,p,q;};
struct Qry{int id,k,x,y;};
LinkedList<N,N<<1,edge>G;
LinkedList<N,N<<2,Qry>Q;
int dep[N],fa[N],sz[N],son[N],top[N];
int A[N],B[N];
ll Res[N];
int n,K;

void dfs(int u,int f,int d)
{
	dep[u]=d,fa[u]=f,sz[u]=1,son[u]=0;
	EOR(i,G,u)
	{
		int v=G[i].to;
		if(v==f)continue;
		dfs(v,u,d+1);
		sz[u]+=sz[v];
		if(sz[v]>sz[son[u]])son[u]=v;
	}
}

void hld(int u,int f,int tp)
{
	top[u]=tp;
	if(son[u])hld(son[u],u,tp);
	EOR(i,G,u)
	{
		int v=G[i].to;
		if(v==f||v==son[u])continue;
		hld(v,u,v);
	}
}

int get_lca(int x,int y)
{
	while(top[x]!=top[y])
	{
		if(dep[top[x]]<dep[top[y]])
			std::swap(x,y);
		x=fa[top[x]];
	}
	return dep[x]<dep[y]?x:y;
}

void DFS(int u,int f,int D)
{
	EOR(i,Q,u)
	{
		Qry q=Q[i];
		Res[q.id]+=q.k*(D-B[q.x]+A[q.x]*q.y);
	}
	EOR(i,G,u)
	{
		int v=G[i].to;
		if(v==f)continue;
		A[G[i].p]++;
		B[G[i].p]+=G[i].q;
		DFS(v,u,D+G[i].q);
		A[G[i].p]--;
		B[G[i].p]-=G[i].q;
	}
}

int main()
{
	scanf("%d%d",&n,&K);
	FOR(i,1,n-1)
	{
		int u,v,p,q;
		scanf("%d%d%d%d",&u,&v,&p,&q);
		G.add(u,(edge){v,p,q}),G.add(v,(edge){u,p,q});
	}
	dfs(1,0,1);
	hld(1,0,1);
	FOR(i,1,K)
	{
		int x,y,u,v;
		scanf("%d%d%d%d",&x,&y,&u,&v);
		Q.add(u,(Qry){i,1,x,y});
		Q.add(v,(Qry){i,1,x,y});
		Q.add(get_lca(u,v),(Qry){i,-2,x,y});
	}
	DFS(1,0,0);
	FOR(i,1,K)printf("%lld\n",Res[i]);
	return 0;
}

### Prompt

Please provide a CPP coded solution to the problem described below:

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 FOR(i,x,y) for(int i=(x),i##END=(y);i<=i##END;++i)
#define DOR(i,x,y) for(int i=(x),i##END=(y);i>=i##END;--i)
template<typename T,typename _T>inline bool chk_min(T &x,const _T y){return y<x?x=y,1:0;}
template<typename T,typename _T>inline bool chk_max(T &x,const _T y){return x<y?x=y,1:0;}
typedef long long ll;
const int P=1e9+7;
const int N=100005;
template<const int maxn,const int maxm,typename T>struct LinkedList
{
	int head[maxn],nxt[maxm],tot;T to[maxm];
	LinkedList(){clear();}
	T &operator [](const int x){return to[x];}
	void clear(){memset(head,-1,sizeof(head)),tot=0;}
	void add(int u,T v){to[++tot]=v,nxt[tot]=head[u],head[u]=tot;}
	#define EOR(i,G,u) for(int i=G.head[u];~i;i=G.nxt[i])
};
struct edge{int to,p,q;};
struct Qry{int id,k,x,y;};
LinkedList<N,N<<1,edge>G;
LinkedList<N,N<<2,Qry>Q;
int dep[N],fa[N],sz[N],son[N],top[N];
int A[N],B[N];
ll Res[N];
int n,K;

void dfs(int u,int f,int d)
{
	dep[u]=d,fa[u]=f,sz[u]=1,son[u]=0;
	EOR(i,G,u)
	{
		int v=G[i].to;
		if(v==f)continue;
		dfs(v,u,d+1);
		sz[u]+=sz[v];
		if(sz[v]>sz[son[u]])son[u]=v;
	}
}

void hld(int u,int f,int tp)
{
	top[u]=tp;
	if(son[u])hld(son[u],u,tp);
	EOR(i,G,u)
	{
		int v=G[i].to;
		if(v==f||v==son[u])continue;
		hld(v,u,v);
	}
}

int get_lca(int x,int y)
{
	while(top[x]!=top[y])
	{
		if(dep[top[x]]<dep[top[y]])
			std::swap(x,y);
		x=fa[top[x]];
	}
	return dep[x]<dep[y]?x:y;
}

void DFS(int u,int f,int D)
{
	EOR(i,Q,u)
	{
		Qry q=Q[i];
		Res[q.id]+=q.k*(D-B[q.x]+A[q.x]*q.y);
	}
	EOR(i,G,u)
	{
		int v=G[i].to;
		if(v==f)continue;
		A[G[i].p]++;
		B[G[i].p]+=G[i].q;
		DFS(v,u,D+G[i].q);
		A[G[i].p]--;
		B[G[i].p]-=G[i].q;
	}
}

int main()
{
	scanf("%d%d",&n,&K);
	FOR(i,1,n-1)
	{
		int u,v,p,q;
		scanf("%d%d%d%d",&u,&v,&p,&q);
		G.add(u,(edge){v,p,q}),G.add(v,(edge){u,p,q});
	}
	dfs(1,0,1);
	hld(1,0,1);
	FOR(i,1,K)
	{
		int x,y,u,v;
		scanf("%d%d%d%d",&x,&y,&u,&v);
		Q.add(u,(Qry){i,1,x,y});
		Q.add(v,(Qry){i,1,x,y});
		Q.add(get_lca(u,v),(Qry){i,-2,x,y});
	}
	DFS(1,0,0);
	FOR(i,1,K)printf("%lld\n",Res[i]);
	return 0;
}

```