#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef vector<ll> v;
typedef vector<v> vv;
typedef vector<vv> vvv;
typedef pair<ll, ll> p;
typedef vector<p> vp;
typedef vector<vp> vvp;
typedef vector<vvp> vvvp;
typedef pair<ll, p> tri;
typedef vector<tri> vtri;
typedef vector<vtri> vvtri;
typedef vector<vvtri> vvvtri;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<vvb> vvvb;

#define f first
#define s second
#define pb push_back
#define eb emplace_back
#define all(v) (v).begin(),(v).end()

const ll INF = 1e18;
const ll mod = 1e9 + 7;

void initStuff(ll i, vv &graph, v &height, v &parent)
{
    for (ll x : graph[i])
    {
        if (height[x] == -1)
        {
            height[x] = height[i] + 1;
            parent[x] = i;
            initStuff(x, graph, height, parent);
        }
    }
}

std::vector<int> solve(
std::vector<std::pair<int, int>> R,
std::vector<long long> D,
std::vector<int> S,
std::vector<int> T,
std::vector<bool> I
)
{
    ll N = R.size() + 1;
    vv graph(N);
    for (ll i = 0; i < N - 1; i++)
    {
        graph[R[i].f].pb(R[i].s);
        graph[R[i].s].pb(R[i].f);
    }
    v height(N, -1);
    height[0] = 0;
    v parent(N, 0);
    initStuff(0, graph, height, parent);
    ll logN = log2(N);
    vv lifting(logN + 1, v(N));
    lifting[0] = parent;
    for (ll iter = 1; iter <= logN; iter++)
    {
        for (ll i = 0; i < N; i++) lifting[iter][i] = lifting[iter - 1][lifting[iter - 1][i]];
    }
    ll M = D.size();
    vector<int> res(M);
    for (ll i = 0; i < M; i++)
    {
        if (!I[i]) continue;
        ll a = S[i], b = T[i];
        ll lca;
        if (height[a] < height[b]) swap(a, b);
        ll diff = height[a] - height[b];
        for (ll i = logN; i >= 0; i--)
        {
            if (diff & (1 << i))
            {
                a = lifting[i][a];
            }
        }
        if (a == b)
        {
            lca = a;
        }
        else
        {
            for (ll i = logN; i >= 0; i--)
            {
                if (lifting[a][i] != lifting[b][i])
                {
                    a = lifting[a][i];
                    b = lifting[b][i];
                }
            }
            lca = parent[a];
        }
        res[i] = height[lca] * 2 - height[S[i]] - height[T[i]];
    }
    return res;
}
/*

signed main() {
    int n, m;

    std::cin >> n;
    std::cin >> m;

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

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

    for (int i = 0; i < m; i++) {
        long long _d, _s, _t, _i;
        std::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) {
        std::cout << it << std::endl;
    }

    return 0;
}
/**/