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

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<long long> vll;
typedef vector<vll> vvll;
typedef pair<int, int> ii;
typedef vector<ii> vii;

int n, m;
vvi adj;

vi bfs(int d, int t) {
    vll dist(m, -1);
    dist[d] = 0;
    vi parent(m, -1);
    parent[d] = -1;
    queue<int> q;
    q.push(d);
    while (!q.empty()) {
        int p = q.front();
        q.pop();
        for (auto node : adj[p]) {
            if (dist[node] == -1) {
                parent[node] = p;
                dist[node] = dist[p]+1;
                q.push(node);
            }
        }
    }
    vi ans;
    int i = t;
    while (i!=-1) {
        ans.push_back(i);
        i = parent[i];
    }
    reverse(ans.begin(), ans.end());
    return ans;
}

int main() {
    //ios::sync_with_stdio(0);
    //cin.tie(NULL);
    cin >> n >> m;
    adj.resize(n);
    bool firstsubtask = 1;
    vi d(m);
    vi s(m);
    vi t(m);
    vvi cities(n);
    vector<bool> I(m);
    for (int i = 0;i<n-1;++i) {
        int a, b;
        cin >> a >> b;
        adj[a].push_back(b);
        adj[b].push_back(a);
    }
    for (int i = 0;i<m;++i) {
        bool can;
        cin >> d[i] >> s[i] >> t[i] >> can;
        I[i] = can;
        if (d[i] != 0) {
            firstsubtask = 0;
        }
        cities[s[i]].push_back(i);
    }
    if (firstsubtask) {
        vvi paths;
        int days = 0;
        for (int i = 0;i<m;++i) {
            paths.push_back(bfs(s[i], t[i]));
            if (days < paths[i].size())
                days = paths[i].size();
        }
        vi ans(m, 0);
        for (int i = 0;i<days;++i) {
            for (int j = 0;j<m;++j) {
                if (i >= paths[j].size())
                    continue;
                int curcity = paths[j][i];
                if (I[j]) {
                    ans[j]++;
                    continue;
                }
                for (int man : cities[curcity]) {
                    if (man == -1)
                        continue;
                    if (I[man]) {
                        I[j] = 1;
                        ans[j]++;
                        break;
                    }
                }
            }
            for (int j = 0;j<m;++j) {
                if (i >= paths[j].size())
                    continue;
                vi city = cities[paths[j][i]];
                for (int k = 0;k<city.size();++k) {
                    if (city[k] == j) {
                        if (i+1 != paths[j].size()){
                            cities[paths[j][i]][k] = -1;
                            cities[paths[j][i+1]].push_back(j);
                        }
                        break;
                    }
                }
            }
        }

        for (int a : ans) {
            cout << a << '\n';
        }
    }
    return 0;
}