#include<bits/stdc++.h>
#define ll long long
#define fr(i , a , b) for(ll i = a ; i <= b ; ++i)
#define fo(i , a , b) for(ll i = a ; i >= b ; --i)
using namespace std;
ll n , q;
struct node
{
    ll to , nxt;
}edge[2000001];
ll head[2000001] , num_edge;
inline void add(ll u , ll v)
{
    edge[++num_edge].to = v;
    edge[num_edge].nxt = head[u];
    head[u] = num_edge;
}
ll dep[500001] , siz[500001] , son[500001] , f[500001];
inline void dfs1(ll u , ll fa)
{
    dep[u] = dep[fa] + 1;
    siz[u] = 1;
    f[u] = fa;
    for(ll i = head[u] ; i ; i = edge[i].nxt)
    {
        ll v = edge[i].to;
        if(v == fa)
        {
            continue;
        }
        dfs1(v , u);
        siz[u] += siz[v];
        if(siz[son[u]] < siz[v])
        {
            son[u] = v;
        }
    }
}
ll h[500001];
inline void dfs2(ll u , ll heap)
{
    h[u] = heap;
    if(son[u])
    {
        dfs2(son[u] , heap);
    }
    for(ll i = head[u] ; i ; i = edge[i].nxt)
    {
        ll v = edge[i].to;
        if(v == f[u] || v == son[u])
        {
            continue;
        }
        dfs2(v , v);
    }
}
inline ll lca(ll x , ll y)
{
    if(h[x] == h[y])
    {
        return dep[x] < dep[y] ? x : y;
    }
    while(h[x] != h[y])
    {
        if(dep[h[x]] < dep[h[y]])
        {
            swap(x , y);
        }
        x = f[x];
    }
    return dep[x] < dep[y] ? x : y;
}
struct Node
{
    ll num , id;
}st_max[500005][21] , st_min[500005][21];
inline void get_st()
{
    ll t = log(n) / log(2);
    memset(st_min , 5000005 , sizeof st_min);
    fr(i , 1 , n)
    {
        st_max[i][0].num = dep[i];
        st_max[i][0].id = i;
        st_min[i][0].num = dep[i];
        st_min[i][0].id = i;
    }
    fr(j , 1 , t)
    {
        for(ll i = 1 ; i + (1 << j) - 1 <= n ; i++)
        {
            if(st_max[i][j - 1].num > st_max[i + (1 << (j - 1))][j - 1].num)
            {
                st_max[i][j].id = st_max[i][j - 1].id;
            }
            else
            {
                st_max[i][j].id = st_max[i + (1 << (j - 1))][j - 1].id;
            }
            st_max[i][j].num = max(st_max[i][j - 1].num , st_max[i + (1 << (j - 1))][j - 1].num);
            if(st_min[i][j - 1].num < st_min[i + (1 << (j - 1))][j - 1].num)
            {
                st_min[i][j].id = st_min[i][j - 1].id;
            }
            else
            {
                st_min[i][j].id = st_min[i + (1 << (j - 1))][j - 1].id;
            }
            st_min[i][j].num = min(st_min[i][j - 1].num , st_min[i + (1 << (j - 1))][j - 1].num);
        }
    }
    // fr(j , 0 , t)
    // {
    // 	fr(i , 1 , n)
    // 	{
    // 		cout << st_min[i][j].num << ' ';
	// 	}
	// 	cout << '\n';
	// }
}
inline ll get_max(ll l , ll r)
{
    ll kkk = log(r - l + 1) / log(2);
    if(st_max[l][kkk].num > st_max[r - (1 << kkk) + 1][kkk].num)
    {
        return st_max[l][kkk].id;
    }
    return st_max[r - (1 << kkk) + 1][kkk].id;
}
inline ll get_min(ll l , ll r)
{
    ll kkk = log(r - l + 1) / log(2);
    // cout << "##" << kkk << '\n';
    if(st_min[l][kkk].num < st_min[r - (1 << kkk) + 1][kkk].num)
    {
        return st_min[l][kkk].id;
    }
    return st_min[r - (1 << kkk) + 1][kkk].id;
}
signed main()
{
	freopen("query.in" , "r" , stdin);
	freopen("query.out" , "w" , stdout); 
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cin >> n;
    fr(i , 2 , n)
    {
        ll u , v;
        cin >> u >> v;
        add(u , v);
        add(v , u);
    }
    dfs1(1 , 1);
    dfs2(1 , 1);
    get_st();
    cin >> q;
    while(q--)
    {
        ll l , r , k;
        cin >> l >> r >> k;
        if(r - l + 1 == k)
        {
            cout << dep[f[get_min(l , r)]] << '\n';
        }
        else if(n <= 500)
        {
            ll ans = 1;
            fr(len , k , r - l + 1)
            {
                for(ll le = l ; le + len - 1 <= r ; le++)
                {
                    ll ri = le + len - 1 , minn = 0x7fffffff , maxn = -1 , id1 = 0 , id2 = 0;
                    fr(i , le , ri)
                    {
                        if(maxn < dep[i])
                        {
                            maxn = dep[i];
                            id1 = i;
                        }
                    }
                    fo(i , ri , le)
                    {
                        if(minn > dep[i])
                        {
                            minn = dep[i];
                            id2 = i;
                        }
                    }
                    ll xx = lca(id1 , id2);
                    if(ans < dep[xx])
                    {
                        ans = dep[xx];
                    }
                }
            }
            cout << ans << '\n';
        }
        else if(n <= 5000)
        {
            ll ans = 1;
        	fr(len , k , r - l + 1)
        	{
        		for(ll le = l ; le + len - 1 <= r ; le++)
        		{
					ll ri = le + len - 1;
                    ll x = get_max(le , ri) , y = get_min(le , ri);
                    ll xx = lca(x , y);
                    if(x == y && len != 1)
                    {
                        xx = f[x];
                    }
                    if(ans < dep[xx])
                    {
                        // cout << "!!" << xx << ' ' << le << ' ' << ri << '\n';
                        // cout << "@@" << x << ' ' << y << '\n';
                        ans = dep[xx];
                    }
				}
			}
            cout << ans << '\n';
		}
        else
        {
            cout << dep[get_min(l , r)] << '\n';
        }
    }
    return 0;
}
