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

int n,m;
vector<vector<int>> L;
vector<int> solve(vector<pair<int, int>> R, vector<ll> D, vector<int> S, vector<int> T, vector<bool> I)
{
    n = R.size()+1;
    m = D.size();
    L = vector<vector<int>>(n);
    for (auto [a,b] : R)
    {
        L[a].push_back(b);
        L[b].push_back(a);
    }
    map<pair<ll, ll>, vector<int>> mp;
    vector<int> path_len(m, -1);
    for (int i = 0; i < m; i++)
    {
        vector<int> back = vector<int>(n, -1);
        vector<ll> dist = vector<ll>(n, LLONG_MAX);
        dist[S[i]] = D[i];
        queue<int> q;
        q.push(S[i]);
        while (q.size())
        {
            int u = q.front();
            q.pop();
            for (auto v : L[u])
            {
                if (dist[u]+1 < dist[v])
                {
                    dist[v] = dist[u]+1;
                    back[v] = u;
                    q.push(v);
                }
            }
        }
        int p = T[i];
        int cnt= 1;
        while (p!=S[i])
        {
            cnt++;
            mp[{p, dist[p]}].push_back(i);
            p = back[p];
        }
        path_len[i] = cnt;
        mp[{p, dist[p]}].push_back(i);
    }
    vector<pair<int,vector<int>>> events;
    for (auto [point, vec] : mp)
    {
        if (vec.size() < 2) continue;
        events.push_back({point.second, vec});
    }
    sort(events.begin(), events.end());
    vector<ll> first_infect(m, LLONG_MAX);
    for (int i = 0; i < m; i++)
    {
        if (I[i])
            first_infect[i] = D[i];
    }
    for (auto [time, part] : events)
    {
        bool dirty = false;
        for (auto p : part)
            if (first_infect[p]!=LLONG_MAX)
            {
                dirty = true;
                break;
            }
        if (!dirty) continue;
        for (auto p : part)
        {
            first_infect[p] = min(first_infect[p], (ll)time);
        }
    }
    vector<int> ans(m, -1);
    for (int i = 0; i < m; i++)
    {
        ans[i] = max(0ll, path_len[i]-first_infect[i]+D[i]);
    }
    return ans;
}

#ifdef DEBUG
signed main() {
    int n, m;

    cin >> n;
    cin >> m;

    vector<pair<int, int>> edges = {};
    vector<long long> day;
    vector<int> start;
    vector<int> target;
    vector<bool> infected;

    for (int i = 0; i < n - 1; i++) {
        int u, v;
        cin >> u >> v;
        edges.emplace_back(u, v);
    }

    for (int i = 0; i < m; i++) {
        long long _d, _s, _t, _i;
        cin >> _d >> _s >> _t >> _i;
        day.push_back(_d);
        start.push_back(_s);
        target.push_back(_t);
        infected.push_back(_i);
    }

    const auto ans = solve(edges, day, start, target, infected);
    for (const auto it : ans) {
        cout << it << endl;
    }

    return 0;
}
#endif