#include <bits/stdc++.h>
using namespace std;
#define int long long

vector<int> height(0);

void dfs_height(vector<vector<pair<int, pair<int, int>>>> &t, int v, int parent, int val){
	height[v] = val;
	for(int i = 0; i < t[v].size(); i++){
		if(t[v][i].first != parent){
			dfs_height(t, t[v][i].first, v, val + 1);
		}
	}
}

void prepair(vector<vector<pair<int, pair<int, int>>>> &t, vector<vector<int>> &anses, int v, int parent){
	if(parent >= 0){
		anses[v].push_back(parent);
	}
	for(int i = 1; (1 << i) <= height[v]; i++){
		anses[v].push_back(anses[anses[v][i - 1]][i - 1]);
	}
	for(int i = 0; i < t[v].size(); i++){
		if(t[v][i].first != parent){
			prepair(t, anses, t[v][i].first, v);
		}
	}
}

void dfs_dist(vector<vector<pair<int, pair<int, int>>>> &t, vector<int> &dist, int v, int parent, int d){
	dist[v] = d;
	for(int i = 0; i < t[v].size(); i++){
		if(t[v][i].first != parent){
			dfs_dist(t, dist, t[v][i].first, v, d + t[v][i].second.second);
		}
	}
}

void dfs_dist_s(vector<vector<pair<int, pair<int, int>>>> &t, vector<int> &dist, int v, int parent, int d, int c){
	dist[v] = d;
	for(int i = 0; i < t[v].size(); i++){
		if(t[v][i].first != parent){
			dfs_dist_s(t, dist, t[v][i].first, v, d + (c == t[v][i].second.first ? 0 : t[v][i].second.second), c);
		}
	}
}

void dfs_ccount_s(vector<vector<pair<int, pair<int, int>>>> &t, vector<int> &ccount, int v, int parent, int val, int c){
	ccount[v] = val;
	for(int i = 0; i < t[v].size(); i++){
		if(t[v][i].first != parent){
			dfs_ccount_s(t, ccount, t[v][i].first, v, val + (c == t[v][i].second.first ? 1 : 0), c);
		}
	}
}

int LCA(vector<vector<int>> &anses, int u, int v){
//	printf("LCA(%d, %d)\n", u, v);
	int hu = height[u], hv = height[v], i;
	if(hu != hv){
		if(hu > hv){
			swap(u, v);
			swap(hu, hv);
		}
		for(i = anses[v].size() - 1; i >= 0; i--){
			if(i < anses[v].size() && hu <= hv - (1 << i)){
				v = anses[v][i];
				hv = height[v];
			}
		}
	}
//	printf("(u, v) = (%d, %d)\n", u, v);
	if(u == v){
		return u;
	}
	for(i = anses[u].size() - 1; i >= 0; i--){
		if(i < anses[u].size() && i < anses[v].size() && anses[u][i] != anses[v][i]){
			u = anses[u][i];
			v = anses[v][i];
		}
	}
	return anses[u][0];
}

int on_pass(vector<vector<int>> &anses, int u, int v, int lca, int a){
	if(LCA(anses, u, a) == lca && LCA(anses, v, a) == a){
		return 1;
	}
	if(LCA(anses, u, a) == a && LCA(anses, v, a) == lca){
		return 1;
	}
	return 0;
}

signed main(){
	int B = 300;
	int N, Q, a, b, c, d, i, j;
	scanf("%lld%lld", &N, &Q);
	vector<vector<pair<int, pair<int, int>>>> t(N, vector<pair<int, pair<int, int>>>(0));
	vector<vector<pair<pair<int, int>, int>>> ces(N, vector<pair<pair<int, int>, int>>(0));
	for(i = 1; i < N; i++){
		scanf("%lld%lld%lld%lld", &a, &b, &c, &d);
		a--;
		b--;
		c--;
		t[a].push_back(pair<int, pair<int, int>>(b, pair<int, int>(c, d)));
		t[b].push_back(pair<int, pair<int, int>>(a, pair<int, int>(c, d)));
		ces[c].push_back(pair<pair<int, int>, int>(pair<int, int>(a, b), d));
	}
//	printf("test2:%d\n", ces[0].size());
	for(i = 0; i < N; i++){
		height.push_back(-1);
	}
	dfs_height(t, 0, -1, 0);
	vector<vector<int>> anses(N, vector<int>(0));
	vector<int> dist(N);
	dfs_dist(t, dist, 0, -1, 0);
	prepair(t, anses, 0, -1);
	vector<vector<int>> dist_s(0), ccount_s(0);
	for(i = 0; i < N; i++){
		if(ces[i].size() >= B){
			dist_s.push_back(vector<int>(N));
			ccount_s.push_back(vector<int>(N));
			dfs_dist_s(t, dist_s[i], 0, -1, 0, i);
			dfs_ccount_s(t, ccount_s[i], 0, -1, 0, i);
		}
		else{
			dist_s.push_back(vector<int>(0));
			ccount_s.push_back(vector<int>(0));
		}
	}
/*	for(i = 0; i < N; i++){
		printf("dist_s[0][%d] = %d\n", i, dist_s[0][i]);
	}
*/	for(i = 0; i < Q; i++){
		int x, y, u, v;
		scanf("%lld%lld%lld%lld", &x, &y, &u, &v);
		x--;
		u--;
		v--;
		int lca, ans, cnt;
		lca = LCA(anses, u, v);
//		printf("lca = %d\n", lca);
//		printf("ces[%d].size() = %d\n", x, ces[x].size());
		if(ces[x].size() >= B){
			ans = dist_s[x][u] + dist_s[x][v] - 2 * dist_s[x][lca];
			cnt = ccount_s[x][u] + ccount_s[x][v] - 2 * ccount_s[x][lca];
//			printf("(ans, cnt) = (%d, %d)\n", ans, cnt);
			ans += y * cnt;
		}
		else{
			ans = dist[u] + dist[v] - 2 * dist[lca];
//			printf("ans(no change) = %d\n", ans);
			for(j = 0; j < ces[x].size(); j++){
				a = ces[x][j].first.first;
				b = ces[x][j].first.second;
				d = ces[x][j].second;
//				printf("(a, b, d) = (%d, %d, %d)\n", a, b, d);
				if(on_pass(anses, u, v, lca, a) == 1 && on_pass(anses, u, v, lca, b) == 1){
//					printf("test4\n");
					ans += y - d;
				}
			}
		}
		printf("%lld\n", ans);
	}
	return 0;
}

Measured memory_bytes: 48560