#include <bits/stdc++.h>
using namespace std;
const int N=1e4+514;
int father[N],height[N],grion[N][N],lg2[N],n;
vector<int> tree[N];
void gener(int a,int b)
{
	int x=a,y=b;
	if(grion[a][b]) return;
	if(height[a]<height[b]) swap(a,b); 
	while(height[a]!=height[b])
	{
		if(grion[a][b]) 
		{
			grion[x][y]=grion[y][x]=grion[a][b];
			return;
		}
		a=father[a];
	} 
	while(a!=b)
	{
		a=father[a];
		b=father[b];
		if(grion[a][b]){
			grion[x][y]=grion[y][x]=grion[a][b];
			break;
		}
	}
	grion[x][y]=grion[y][x]=a;
}
int hcount(int p,int fa)
{
	for(int i:tree[p])
	{
		if(i==fa) continue;
		height[i]=height[p]+1;
		hcount(i,p);
		
	}
	father[p]=fa;
}
int main()
{
	freopen("query.in","r",stdin);
	freopen("query.out","w",stdout); 
	int n;
	cin>>n;
	for(int i=1;i<n;++i){
		int u,v;
		cin>>u>>v;
		tree[u].push_back(v);
		tree[v].push_back(u);
	} 
	height[1]=1; 
	hcount(1,0);

	int q;
	cin>>q;
	for(int i=1;i<=n;++i) grion[i][i]=i;
	for(int i=1;i<=n;++i)
		for(int j=i+1;j<=n;++j)
			gener(i,j);
	while(q--)
	{
		int l,r,k,d,maxn=-1;
		cin>>l>>r>>k;
		for(int i=l;i<=r-k+1;++i)
		{
			d=i;
			for(int j=i+1;j<=i+k-1;++j) d=grion[j][d];
			maxn=max(maxn,height[d]);
		 } 
		 cout<<maxn<<endl;
	}
}
 
