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

const int N = 5e5 +10;

int n, q;
vector<int> g[N];
int dep[N], stdep[N][25], logg[N];

void dfs(int, int);

int main()
{
    freopen("query.in", "r", stdin);
    freopen("query.out", "w", stdout);
    scanf("%d", &n);
    for (int i = 1; i < n; i++)
    {
        int u, v;
        scanf("%d%d", &u, &v);
        g[u].push_back(v);
        g[v].push_back(u);
    }
    dep[1] = 1;
    dfs(1, 0);
    for (int i = 1; i <= n; i++)
    {
        stdep[i][0] = dep[i];
        if (i > 1)
            logg[i] = logg[i / 2] + 1;
    }
    for (int i = 1; i <= logg[n]; i++)
    {
        for (int j = 1; j + (1 << i) - 1 <= n; j++)
        {
            stdep[j][i] = max(stdep[j][i - 1], stdep[j + (1 << (i - 1))][i - 1]);
        }
    }
    scanf("%d", &q);
    while (q--)
    {
        int l, r, k;
        scanf("%d%d%d", &l, &r, &k);
        int res = max(stdep[l][logg[r - l +1]], stdep[r - (1 << (logg[r - l + 1])) + 1][logg[r - l +1]]);
        printf("%d\n", res);
    }
}

void dfs(int u, int fa)
{
    for (auto v : g[u])
    {
        if (v == fa)
            continue;
        dep[v] = dep[u] + 1;
        dfs(v, u);
    }
}
