#include <bits/stdc++.h>

#define int long long

using namespace std;

#define fileio(x,y) freopen(x,"r",stdin),freopen(y,"w",stdout)
#define tup tuple<int,int,int>
#define pii pair<int,int>
#define pb emplace_back
#define i12 __int128_t
#define mt make_tuple
#define mp make_pair

const int   maxn=5e5+10;
const int   mod=1e9+7;

vector<int> road[maxn];
bool        speA=true;
int         dfn1[30][maxn],dfn2[30][maxn];
int         st[30][2*maxn];
int         lg2[2*maxn];
int         dep[maxn];
int         n,q,cnt;

int get1(int l,int r) { int k=lg2[r-l+1]; return min(dfn1[k][l],dfn1[k][r-(1<<k)+1]); }
int get2(int l,int r) { int k=lg2[r-l+1]; return max(dfn2[k][l],dfn2[k][r-(1<<k)+1]); }
int get3(int l,int r) { int k=lg2[r-l+1]; return min(st[k][l],st[k][r-(1<<k)+1]); }

int calc(int l,int r)
{
    int ll=get1(l,r),rr=get2(l,r);
    return get3(ll,rr);
}

void dfs(int root,int fa)
{
    dep[root]=dep[fa]+1;
    st[0][++cnt]=dep[root];
    dfn1[0][root]=dfn2[0][root]=cnt;
    int ch=0;
    for(int it:road[root])
    {
        if(it==fa) continue;
        ch++; dfs(it,root);
        st[0][++cnt]=dep[root];
    }
    speA&=(ch<=1);
    return;
}

void work()
{
    /* Code */
    cin>>n;
    for(int i=1,x,y; i<n; i++) cin>>x>>y,road[x].pb(y),road[y].pb(x);
    dfs(1,0);
    // cerr<<cnt<<'\n'; return;
    // for(int i=1; i<=cnt; i++) cout<<st[0][i]<<' '; cout<<'\n';
    lg2[0]=-1; for(int i=1; i<=cnt; i++) lg2[i]=lg2[i>>1]+1;
    for(int k=1; k<=lg2[cnt]; k++)
        for(int l=1,r=(1<<k); r<=cnt; l++,r++)
            st[k][l]=min(st[k-1][l],st[k-1][l+(1<<(k-1))]);
    for(int k=1; k<=lg2[n]; k++)
        for(int l=1,r=(1<<k); r<=n; l++,r++)
            dfn1[k][l]=min(dfn1[k-1][l],dfn1[k-1][l+(1<<(k-1))]),
            dfn2[k][l]=max(dfn2[k-1][l],dfn2[k-1][l+(1<<(k-1))]);
    // cerr<<speA<<'\n';
    if(speA)
    {
        cin>>q;
        for(int i=1,l,r,k; i<=q; i++)
        {
            cin>>l>>r>>k;
            cout<<max(calc(l,l+k-1),calc(r-k+1,r))<<'\n';
        }
        return;
    }
    cin>>q;
    for(int i=1,l,r,k; i<=q; i++)
    {
        cin>>l>>r>>k; int tar=0;
        for(int ll=l,rr=l+k-1; rr<=r; ll++,rr++) tar=max(tar,calc(ll,rr));
        cout<<tar<<'\n';
    }
    return;
}

signed main()
{
    fileio("query.in","query.out");
    ios::sync_with_stdio(false);
    cin.tie(0);
    int t,stTime=clock();
    t=1;
    while(t--) work();
    // cerr<<"Time : "<<(double)(clock()-stTime)/CLOCKS_PER_SEC<<'\n';
    return 0;
}