#include<iostream>
#include<vector>
using namespace std;
#define N 500010
int n,q,mylog[N];
int cnt,fa[N],dep[N],idfn[N][21],adfn[N][21],st[N][21];
vector<int> g[N];
int mymin(int x,int y)
{
	return dep[x]<dep[y]?x:y;
}
int getlca(int l,int r)
{
	if(l==r)
	 return st[l][0];
	int d=mylog[r-l];
	return fa[mymin(st[l+1][d],st[r-(1<<d)+1][d])];
}
int getidfn(int l,int r)
{
	if(l==r)
	 return idfn[l][0];
	int d=mylog[r-l+1];
	return min(idfn[l][d],idfn[r-(1<<d)+1][d]);
}
int getadfn(int l,int r)
{
	if(l==r)
	 return adfn[l][0];
	int d=mylog[r-l+1];
	return max(adfn[l][d],adfn[r-(1<<d)+1][d]);
}
void dfs(int u,int _fa)
{
	fa[u]=_fa;
	cnt++;
//	cerr<<u<<"-->"<<cnt<<endl;
	idfn[u][0]=cnt;
	adfn[u][0]=cnt;
	dep[u]=dep[_fa]+1;
	st[cnt][0]=u;
	for(int v:g[u])
	if(v!=_fa)
	{
		dfs(v,u);
	}
}
int main()
{
	freopen("query.in","r",stdin);
	freopen("query.out","w",stdout);
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	for(int i=2;i<N;i++)
	 mylog[i]=mylog[i>>1]+1;
	cin>>n;
	for(int i=1;i<=n-1;i++)
	{
		int u,v;
		cin>>u>>v;
		g[u].push_back(v);
		g[v].push_back(u);
	}
	dfs(1,0);
	for(int j=1;j<=20;j++)
	for(int i=1;i<=n;i++)
	if(i+(1<<j-1)<=n)
	{
		st[i][j]=mymin(st[i][j-1],st[i+(1<<j-1)][j-1]);
		idfn[i][j]=min(idfn[i][j-1],idfn[i+(1<<j-1)][j-1]);
		adfn[i][j]=max(adfn[i][j-1],adfn[i+(1<<j-1)][j-1]);
	}
	cin>>q;
	for(int i=1;i<=q;i++)
	{
		int l,r,k;
		cin>>l>>r>>k;
		int ans=0;
		for(int j=l;j+k-1<=r;j++)
		{
			int mi=getidfn(j,j+k-1);
			int ma=getadfn(j,j+k-1);
			int lca=getlca(mi,ma);
//			cerr<<j<<" "<<j+k-1<<"::"<<mi<<" "<<ma<<"|"<<lca<<endl;
			ans=max(ans,dep[lca]);
		}
		cout<<ans<<"\n";
	}
}
