#include <iostream>
#include <vector>
#include <map>
#include <utility>
#include <functional>
using namespace std;

class LCA
{
    int n;
    vector<vector<int>> P;
    vector<int> D;

public:
    //  a in E[b] <=> b in E[a]
    LCA(vector<vector<int>> E, int root)
    {
        n = (int)E.size();
        P = vector<vector<int>>(n);
        D = vector<int>(n);

        function<void (int, int, int)> f = [&](int c, int p, int d)
        {
            D[c] = d;
            
            if (d>0)
                P[c].push_back(p);
            for (int i=1; 1<<i<=d; i++)
                P[c].push_back(P[P[c][i-1]][i-1]);
            
            for (int e: E[c])
                if (e != p)
                    f(e, c, d+1);
        };
        f(root, -1, 0);
    }

    int query(int a, int b)
    {
        if (D[a]>D[b])
            swap(a, b);

        int d = D[b]-D[a];
        for (int i=0; d>0; i++)
        {
            if (d&1)
                b = P[b][i];
            d >>= 1;
        }

        if (a==b)
            return a;

        int i = 0;
        while (1<<(i+1)<=D[a])
            i++;
        for (; i>=0; i--)
            if (1<<i<=D[a] && P[a][i]!=P[b][i])
            {
                a = P[a][i];
                b = P[b][i];
            }

        if (D[a]>0)
            a = P[a][0];
        return a;
    }
};

int main()
{
    int N, Q;
    cin>>N>>Q;
    vector<vector<int>> E(N);
    vector<vector<int>> EC(N);
    vector<vector<int>> ED(N);
    for (int i=0; i<N-1; i++)
    {
        int a, b, c, d;
        cin>>a>>b>>c>>d;
        a--;
        b--;
        c--;
        E[a].push_back(b);
        EC[a].push_back(c);
        ED[a].push_back(d);
        E[b].push_back(a);
        EC[b].push_back(c);
        ED[b].push_back(d);
    }

    vector<int> S;
    vector<vector<int>> CI(N-1);
    vector<vector<int>> CS(N-1);
    vector<vector<int>> CN(N-1);
    vector<int> VI(N);

    S.push_back(0);
    for (int c=0; c<N-1; c++)
    {
        CI[c].push_back(0);
        CS[c].push_back(0);
        CN[c].push_back(0);
    }

    int idx = 0;
    function<void (int, int)> f = [&](int c, int p)
    {
        VI[c] = idx;

        for (int i=0; i<(int)E[c].size(); i++)
            if (E[c][i] != p)
            {
                idx++;
                S.push_back(S.back()+ED[c][i]);
                int cc = EC[c][i];
                CI[cc].push_back(idx);
                CS[cc].push_back(CS[cc].back()+ED[c][i]);
                CN[cc].push_back(CN[cc].back()+1);

                f(E[c][i], c);

                idx++;
                S.push_back(S.back()-ED[c][i]);
                CI[cc].push_back(idx);
                CS[cc].push_back(CS[cc].back()-ED[c][i]);
                CN[cc].push_back(CN[cc].back()-1);
            }
    };
    f(0, -1);

    LCA lca(E, 0);

    auto g = [&](int c, int v)
    {
        int idx = VI[v];
        int i = 0;
        while (1<<(i+1)<=(int)CI[c].size())
            i++;
        int r = 0;
        for (; i>=0; i--)
            if (r+(1<<i)<(int)CI[c].size() &&
                CI[c][r+(1<<i)]<=idx)
                r += 1<<i;
        return r;
    };

    for (int i=0; i<Q; i++)
    {
        int x, y, u, v;
        cin>>x>>y>>u>>v;
        x--;
        u--;
        v--;
        int a = lca.query(u, v);
        int ui = g(x, u);
        int vi = g(x, v);
        int ai = g(x, a);

        cout<<
            + (S[VI[u]] + S[VI[v]] - 2*S[VI[a]])
            - (CS[x][ui] + CS[x][vi] - 2*CS[x][ai])
            + (CN[x][ui] + CN[x][vi] - 2*CN[x][ai])*y<<endl;
    }

}


Measured memory_bytes: 59352