#include <bits/stdc++.h>
using namespace std;
#define m_p make_pair
const int N = 100005;

int n, qq;
vector<int> a[N];
vector<pair<int, int> > b[N];

int q[N], pp[N], heavy[N], dd[N];
void dfs0(int x, int p)
{
    dd[x] = dd[p] + 1;
    pp[x] = p;
    q[x] = 1;
    for (int i = 0; i < a[x].size(); ++i)
    {
        int h = a[x][i];
        if (p == h)
            continue;
        dfs0(h, x);
        q[x] + q[h];
        if (!heavy[x] || q[h] > q[heavy[x]])
            heavy[x] = h;
    }
}

map<int, int> mpd[N * 4], mpq[N * 4];
int t[N * 4];
void t_ubd(int tl, int tr, int x, int c, int d, int pos)
{
    t[pos] += d;
    mpd[pos][c] += d;
    mpq[pos][c]++;
    if (tl == tr)
    {
        return;
    }
    int m = (tl + tr) / 2;
    if (x <= m)
        t_ubd(tl, m, x, c, d, pos * 2);
    else
        t_ubd(m + 1, tr, x, c, d, pos * 2 + 1);
}
struct ban
{
    int d, dc, q;
    ban(){}
    ban(int d, int dc, int q)
    {
        this->d = d;
        this->dc = dc;
        this-> q = q;
    }
};
ban mer(const ban& a, const ban& b)
{
    ban res;
    res.d = a.d + b.d;
    res.q = a.q + b.q;
    res.dc = a.dc + b.dc;
    return res;
}
ban t_qry(int tl, int tr, int l, int r, int c, int pos)
{
    if (l > r)
        return ban(0, 0, 0);
    if (tl == l && tr == r)
    {
        if (mpd[pos].find(c) != mpd[pos].end())
            return ban(t[pos], mpd[pos][c], mpq[pos][c]);
        return ban(t[pos], 0, 0);
    }
    int m = (tl + tr) / 2;
    if (r <= m)
        return t_qry(tl, m, l, r, c, pos * 2);
    if (l > m)
        return t_qry(m + 1, tr, l, r, c, pos * 2 + 1);
    return mer(t_qry(tl, m, l, m, c, pos * 2), t_qry(m + 1, tr, m + 1, r, c, pos * 2 + 1));
}

int u[N];

int zt, zd = 1;
int ht[N], hd[N], hq[N], f[N];
void dfs(int x, int p, int c, int d)
{
    hd[x] = zd;
    if (hq[hd[x]] == 0)
    {
        f[hd[x]] = x;
    }
    hq[hd[x]]++;
    ht[x] = ++zt;
    t_ubd(1, n, ht[x], c, d, 1);
    for (int i = 0; i < a[x].size(); ++i)
    {
        int h = a[x][i];
        if (h == heavy[x])
        {
            dfs(heavy[x], x, b[x][i].first, b[x][i].second);
            break;
        }
    }
    for (int i = 0; i < a[x].size(); ++i)
    {
        int h = a[x][i];
        if (h == p || h == heavy[x])
            continue;
        ++zd;
        dfs(h, x, b[x][i].first, b[x][i].second);
    }
}

int qry(int x, int y, int c, int d)
{
    int ans = 0;
    while (1)
    {
        if (hd[x] == hd[y])
            break;
        int xx = f[hd[x]];
        int yy = f[hd[y]];
        if (dd[xx] < dd[yy])
        {
            swap(xx, yy);
            swap(x, y);
        }
        ban yans = t_qry(1, n, ht[xx], ht[x], c, 1);
        ans += yans.d;
        ans -= yans.dc;
        ans += (yans.q * d);
        x = pp[xx];
    }
    if (dd[x] < dd[y])
    {
        swap(x, y);
    }
    ban yans = t_qry(1, n, ht[y] + 1, ht[x], c, 1);
    ans += yans.d;
    ans -= yans.dc;
    ans += (yans.q * d);
    return ans;
}

int main()
{
    scanf("%d%d", &n, &qq);
    for (int i = 0; i < n - 1; ++i)
    {
        int x, y, c, d;
        scanf("%d%d%d%d", &x, &y, &c, &d);
        a[x].push_back(y);
        a[y].push_back(x);
        b[x].push_back(m_p(c, d));
        b[y].push_back(m_p(c, d));
    }
    dfs0(1, 1);
    dfs(1, 1, 0, 0);
    while (qq--)
    {
        int c, d, x, y;
        scanf("%d%d%d%d", &c, &d, &x, &y);
        printf("%d\n", qry(x, y, c, d));
    }
    return 0;
}


Measured memory_bytes: 169336