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

Solution (in CPP):

Solution:
#include<bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define fst first
#define snd second
using namespace std;

typedef long long ll;
typedef double db;
typedef long double ldb;

template<class T> inline void checkmin(T &a,const T &b){if(b<a) a=b;}
template<class T> inline void checkmax(T &a,const T &b){if(b>a) a=b;}

const int inf=1e9+10;
const int maxn=1e5+10;

struct dwl{
	int flag,col,idx,len;
};

int sum[maxn],dist[maxn],len[maxn],ans[maxn];
int n,q;
vector <pair<int,pair<int,int> > > g[maxn];
vector <dwl> dw[maxn];

int parent[20][maxn],dep[maxn];
 
void dfs(int x,int p,int d){
	parent[0][x]=p;
	dep[x]=d;
	for(int i=0;i<g[x].size();i++){
		int to=g[x][i].fst;
		if(to==p) continue;
		dfs(to,x,d+1);
	}
}
 
void build_lca(){
	for(int k=0;k+1<20;k++){
		for(int i=0;i<n;i++){
			if(parent[k][i]==-1) parent[k+1][i]=-1;
			else parent[k+1][i]=parent[k][parent[k][i]]; 
		}
	}	
}
 
int get_lca(int u,int v){
	if(dep[u]>dep[v]) swap(u,v);
	for(int k=0;k<20;k++){
		if((dep[u]-dep[v])>>k&1){
			v=parent[k][v];
		}
	}
	if(u==v) return u;
	for(int k=19;k>=0;k--){
		if(parent[k][u]!=parent[k][v]){
			u=parent[k][u];
			v=parent[k][v];
		}
	}
	return parent[0][u];
}

void dfs(int x,int p){
	for(int i=0;i<dw[x].size();i++){
		if(dw[x][i].flag==1){
			ans[dw[x][i].idx]-=dist[x]*2;
			ans[dw[x][i].idx]+=len[dw[x][i].col]*2;
			ans[dw[x][i].idx]-=sum[dw[x][i].col]*dw[x][i].len*2;
		}
		else{
			ans[dw[x][i].idx]+=dist[x];
		//	cout<<dw[x][i].idx<<" "<<x<<" "<<dist[x]<<endl;
			ans[dw[x][i].idx]-=len[dw[x][i].col];			
			ans[dw[x][i].idx]+=sum[dw[x][i].col]*dw[x][i].len;
		//	cout<<ans[dw[x][i].idx]<<endl;
		}
	}
	for(int i=0;i<g[x].size();i++){
		int to=g[x][i].fst,c=g[x][i].snd.fst,l=g[x][i].snd.snd;
		if(to==p) continue;
		dist[to]=dist[x]+l;
		sum[c]+=1; len[c]+=l;
		dfs(to,x);
		sum[c]-=1; len[c]-=l;
	}
}

int main(){
	for(int d=0;d<20;d++) for(int i=0;i<maxn;i++) parent[d][i]=0;
	scanf("%d%d",&n,&q);
	for(int i=0;i<n-1;i++){
		int u,v,c,l;
		scanf("%d%d%d%d",&u,&v,&c,&l);
		u--; v--; c--;
		g[u].pb(mp(v,mp(c,l)));
		g[v].pb(mp(u,mp(c,l)));
	}
	dfs(0,-1,0);
	build_lca();
	for(int i=0;i<q;i++){
		int c,l,u,v;
		scanf("%d%d%d%d",&c,&l,&u,&v);
		u--; v--; c--;
		int lca=get_lca(u,v);
		dwl now;
		now.flag=0; now.col=c; now.len=l; now.idx=i;
		dw[u].pb(now); dw[v].pb(now);
		now.flag=1;
		dw[lca].pb(now);
	}
	for(int i=0;i<maxn;i++) ans[i]=0;
	dfs(0,-1);
	for(int i=0;i<q;i++) printf("%d\n",ans[i]);
	printf("\n");
	return 0;
}