#include<bits/stdc++.h>
using namespace std;
constexpr int mxn{500005};
int n,q,dep[mxn],st[22][mxn*2],fir[mxn];
vector<int>tree[mxn];
void dfs(int x,int f)
{
	static int cnt=0;
	fir[x]=cnt;
	st[0][cnt++]=x;
    for(int v:tree[x])
    {
        if(v!=f)
        {
            dep[v]=dep[x]+1;
            dfs(v,x);
            st[0][cnt++]=x;
        }
    }
}
int dmin(int x,int y)
{
	if(dep[x]>dep[y])
		return y;
	return x;
}
int LCA(int x,int y)
{
	int l=fir[x],r=fir[y];
	if(l>r)	swap(l,r);
	++r;
	int l2=__lg(r-l);
	return dmin(st[l2][l],st[l2][r-(1<<l2)]);
}
int tr[mxn*4];
int ls(int i){return i*2+1;}
int rs(int i){return i*2+2;}
void ini()
{
	for(int i=1;i<22;++i)
	{
		for(int j=0;j+(1<<i)<=mxn*2;++j)
		{
			st[i][j]=dmin(st[i-1][j],st[i-1][j+(1<<(i-1))]);
		}
	}
	function<void(int,int,int)>sth{[&sth](int l,int r,int i){
		if(r-l==1)
			tr[i]=l;
		else
		{
			int mid=(l+r)>>1;
			sth(l,mid,ls(i));
			sth(mid,r,rs(i));
			tr[i]=LCA(tr[ls(i)],tr[rs(i)]);
		}
	}};
	sth(0,n,0);
}
int LCA2(int L,int R)
{
	function<int(int,int,int)>sth{[L,R,&sth](int l,int r,int i){
		if(L<=l&&r<=R)
			return tr[i];
		else
		{
			int mid=(l+r)>>1;
			if(L<mid&&mid<R)
				return LCA(sth(l,mid,ls(i)),sth(mid,r,rs(i)));
			else if(L<mid)
				return sth(l,mid,ls(i));
			else return sth(mid,r,rs(i));
		}
	}};
	return sth(0,n,0);
}
int solve(int L,int R,int k)
{
	int ans=0;
	for(int i=L+k;i<=R;++i)
	{
		ans=max(ans,dep[LCA2(i-k,i)]);
	}
	return ans;
}
int main()
{
	freopen("query.in","r",stdin);
	freopen("query.out","w",stdout);
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	cin>>n;
    for(int i=1,u,v;i<n;++i)
    {
        cin>>u>>v;--u;--v;
        tree[u].push_back(v);
        tree[v].push_back(u);
    }
    dep[0]=1;
    dfs(0,0);
//    cerr<<LCA(2,4);
//    return 0;
	ini(); 	
	cin>>q;
    for(int i=0,l,r,k;i<q;++i)
	{
		cin>>l>>r>>k;--l;
		cout<<solve(l,r,k)<<'\n';
	}
}
