// #pragma GCC optimize(2)
// #pragma GCC optimize(3)
// #pragma GCC optimize(4)
#include <algorithm>
#include  <iterator>
#include  <iostream>
#include   <cstring>
#include   <cstdlib>
#include   <iomanip>
#include    <bitset>
#include    <cctype>
#include    <cstdio>
#include    <string>
#include    <vector>
#include     <stack>
#include     <cmath>
#include     <queue>
#include      <list>
#include       <map>
#include       <set>
#include   <cassert>
// #include<bits/extc++.h>
// using namespace __gnu_pbds;
using namespace std;
#define pb push_back
#define fi first
#define se second
#define debug(x) cerr<<#x << " := " << x << endl;
#define bug cerr<<"-----------------------"<<endl;
#define FOR(a, b, c) for(int a = b; a <= c; ++ a)

typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

const int inf = 0x3f3f3f3f;
const ll inff = 0x3f3f3f3f3f3f3f3f;
const int mod = 998244353;

template<typename T>
inline T read(T&x){
    x=0;int f=0;char ch=getchar();
    while (ch<'0'||ch>'9') f|=(ch=='-'),ch=getchar();
    while (ch>='0'&&ch<='9') x=x*10+ch-'0',ch=getchar();
    return x=f?-x:x;
}

/**********showtime************/
            const int maxn = 1e5+9;
            vector<int>mp[maxn];
            struct E {
                int u,v;
                int c,d;
                void init(int U, int V ,int C, int D) {
                    u = U;  v = V; c = C; d = D;
                }
            } edge[maxn];
            int dp[maxn];
            int st[maxn ],ed[maxn], tim = 0;
            int fa[maxn][20];
            int a[maxn*2];
            void dfs(int u, int o) {

                dp[u] = dp[o] + 1;
                st[u] = ++tim;
                a[tim] = u;
                fa[u][0] = o;
                for(int i=1; i<20; i++)
                    fa[u][i] = fa[fa[u][i-1]][i-1];
                for(int v : mp[u]) {
                    if(v == o) continue;
                    dfs(v, u);
                }
                ed[u] = ++tim;
                a[tim] = u;
            }
            int lca(int u, int v) {
                if(dp[u] < dp[v]) swap(u, v);
                for(int i=19; i>=0; i--) {
                    if(dp[fa[u][i]] >= dp[v])
                        u = fa[u][i];
                }
                if(u == v) return u;
                for(int i=19; i>=0; i--) {
                    if(fa[u][i] != fa[v][i])
                        u = fa[u][i], v = fa[v][i];
                }
                return fa[u][0];
            }
            int c[maxn], d[maxn];
            struct Q{
//                int u, v;
                int le, ri;
                int lb;
                int x, y;
                int id;
            } qry[maxn];
            bool cmp(Q a, Q b) {
                if(a.lb != b.lb)
                    return a.lb < b.lb;
                return a.ri < b.ri;
            }
            int ans[maxn];
            int sum,colcnt[maxn],colsum[maxn],pot[maxn];
            void add(int id) {

                if(pot[a[id]] == 0) pot[a[id]] = 1;
                else pot[a[id]] = 0;
                int col = c[a[id]];
                if(pot[a[id]]) {
                    colcnt[col] ++;
                    colsum[col] += d[a[id]];
                    sum += d[a[id]];
                }
                else {
                    colcnt[col] --;
                    colsum[col] -= d[a[id]];
                    sum -= d[a[id]];
                }
            }
int main(){
            int n,m;
            scanf("%d%d", &n, &m);
            int block = 2000;
            for(int i=1; i<n; i++) {
                int u,v,c,d;
                scanf("%d%d%d%d", &u, &v, &c, &d);
                edge[i].init(u, v, c, d);
                mp[u].pb(v);
                mp[v].pb(u);
            }
            dfs(1, 1);
            for(int i=1; i<n; i++) {
                int u = edge[i].u, v = edge[i].v;
                if(dp[u] < dp[v]) swap(u, v);
                c[u] = edge[i].c;
                d[u] = edge[i].d;
            }

            for(int i=1; i<=m; i++) {
                int x, y, u, v;
                scanf("%d%d%d%d", &x, &y, &u, &v);
                qry[i].id = i;
                qry[i].x = x;
                qry[i].y = y;
                if(st[u] > st[v]) swap(u, v);
                int _lca = lca(u, v);
                if(_lca == u) {
                    qry[i].le = st[u]+1;
                    qry[i].ri = st[v];
                    qry[i].lb = qry[i].le / block;
                }
                else {
                    qry[i].le = ed[u];
                    qry[i].ri = st[v];
                    qry[i].lb = qry[i].le / block;
                }
            }

            sort(qry+1, qry+1+m, cmp);
            int le = 0, ri = 0;
            for(int i=1; i<=m; i++) {
                while(le < qry[i].le) add(le), le++;
                while(le > qry[i].le) le--, add(le);
                while(ri < qry[i].ri) ri++, add(ri);
                while(ri > qry[i].ri) add(ri), ri--;

                ans[qry[i].id] = sum - colsum[qry[i].x] + colcnt[qry[i].x] * qry[i].y;
            }
            for(int i=1; i<=m; i++) printf("%d\n", ans[i]);
            return 0;
}


Measured memory_bytes: 25856