#include<bits/stdc++.h>
using namespace std;
#define ll long long
const int N=5e5+5,mod=1e9+7;
struct edge{
	int from,to,nxt;
}e[N];
int head[N],ecnt;
void add_edge(int u,int v){
	e[++ecnt]=(edge){u,v,head[u]};
	head[u]=ecnt;
}
bool vis[N];
int dep[N],fth[N][30],lg[N];
ll ans=0;
int cnt=0;
int n,q;
void dfs(int x,int fa){
	dep[x]=dep[fa]+1;
	fth[x][0]=fa;
	for(int i=1;i<=lg[dep[x]]+1;i++){
		fth[x][i]=fth[fth[x][i-1]][i-1];
	}
	for(int i=head[x];i;i=e[i].nxt){
		if(e[i].to==fa)continue;
		dfs(e[i].to,x);
	}
}
int lca(int x,int y){
	if(dep[x]<dep[y])swap(x,y);
	while(dep[x]>dep[y]){
		x=fth[x][lg[dep[x]-dep[y]]];
	}
	if(x==y)return x;
	while(fth[x][0]!=fth[y][0]){
		if(fth[x][lg[dep[x]]]!=fth[y][lg[dep[y]]])
		{
			x=fth[x][lg[dep[x]]];
			y=fth[y][lg[dep[y]]];
		}
	}
	return fth[x][0];
}
int main()
{
	freopen("query.in","r",stdin);
	freopen("query.out","w",stdout);
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	cin>>n;
	for(int i=1;i<n;i++)
	{
		int u,v;
		cin>>u>>v;
		add_edge(u,v);
		add_edge(v,u);
	}
	lg[0]=-1;
	for(int i=1;i<=n;i++){
		lg[i]=lg[i>>1]+1;
	}
	dfs(1,0);
	cin>>q;
	for(int i=1;i<=q;i++){
		int l,r,k;
		int ans=0;
		cin>>l>>r>>k;
		for(int j=l;j<=r-k;j++){
			int now=j;
			for(int g=j+1;g<=j+k;g++){
				now=lca(now,g);
			}
			ans=max(ans,dep[now]);
		}
		cout<<ans<<"\n";
	}
	return 0;
}

