//#include "vision.h"
#include <bits/stdc++.h>
typedef long long ll;
typedef long double ld;
using namespace std;
const int N = 15e4 + 10;
int par[N][20], dst[N];
vector<vector<int>> g;
void dfs(int v, int p) {
    par[v][0] = p;
    dst[v] = dst[p] + 1;
    for (int j = 1; j < 20; j++) {
        par[v][j] = par[par[v][j - 1]][j - 1];
    }
    for (auto it : g[v]) {
        if (it == p) continue;
        dfs(it, v);
    }
}
int lca(int a, int b) {
    if (dst[a] < dst[b]) swap(a, b);
    for (int i = 19; i >= 0; i--) {
        if ((dst[a] - dst[b]) & (1 << i)) a = par[a][i];
    }
    if (a == b) return a;
    for (int i = 19; i >= 0; i--) {
        if (par[a][i] != par[b][i]) {
            a = par[a][i];
            b = par[b][i];
        }
    }
    return par[a][0];
}
int f(int a, int b) {
    return dst[a] + dst[b] - 2 * dst[lca(a, b)] + 1;
}
vector<int> solve(vector<pair<int, int>> R, vector<long long> D, vector<int> S, vector<int> T, vector<bool> I) {
    int n = (int)R.size() + 1;
    int m = (int)D.size();
    vector<int> infdays(m);
    for (int i = 0; i < m; i++) {
        infdays[i] = 0;
    }
    g.clear();
    g.resize(n);
    for (int i = 0; i < n - 1; i++) {
        g[R[i].first].push_back(R[i].second);
        g[R[i].second].push_back(R[i].first);
    }
    dfs(0, 0);
    for (int i = 0; i < m; i++) {
        if (!I[i]) infdays[i] = 0;
        else {
            infdays[i] = f(S[i], T[i]);
        }
    }
    return infdays;
}
/*
int main() {
    int n, m;
    cin >> n >> m;
    vector<pair<int, int>> R(n - 1);
    vector<long long> D(m);
    vector<int> S(m), T(m);
    vector<bool> I = { 1, 0, 0, 0, 0 };
    for (int i = 0; i < n - 1; i++) {
        cin >> R[i].first >> R[i].second;
    }
    for (int i = 0; i < m; i++) {
        cin >> D[i] >> S[i] >> T[i];
    }
    cout << "YEAH\n";
    vector<int> k = solve(R, D, S, T, I);
    for (int i = 0; i < k.size(); i++) {
        cout << k[i] << " ";
    }
    cout << "\n";
}
*/