#include<bits/stdc++.h>
using namespace std;
const int N=1e6+1,L=20;
int n,fa[N][L],dep[N],pre[N],nxt[N],h[N],x,y,q,idx,ans,g[N][L],len,k;
void add(int x,int y){
	h[++idx]=y;
	nxt[idx]=pre[x];
	pre[x]=idx;
}
void dfs(int u,int f){
	dep[u]=dep[fa[u][0]=f]+1;
	for(int i=1;i<L;++i)fa[u][i]=fa[fa[u][i-1]][i-1];
	for(int i=pre[u];i;i=nxt[i])if(h[i]!=f)dfs(h[i],u);
}
int LCA(int x,int y){
	if(dep[x]<dep[y])swap(x,y);
	for(int i=L-1;i>=0;--i)if(dep[fa[x][i]]>=dep[y])x=fa[x][i];
	if(x==y)return x;
	for(int i=L-1;i>=0;--i)if(fa[x][i]!=fa[y][i])x=fa[x][i],y=fa[y][i];
	return fa[x][0];
}
void init(){
	for(int i=1;i<=n;++i)g[i][0]=i;
	for(int k=1;k<L;++k){
		for(int i=1;i<=n;++i){
			g[i][k]=LCA(g[i][k-1],g[i+(1ll<<k)-1][k-1]);
		}
	}
}
int main(){
	freopen("query.in","r",stdin);
	freopen("query.out","w",stdout);
	scanf("%d",&n);
	for(int i=1;i<n;++i)scanf("%d%d",&x,&y),add(x,y),add(y,x);
	dfs(1,0),init();
	scanf("%d",&q);
	while(q--){
		cin>>x>>y>>k;
		len=log2(max(1,k-1)),ans=0;
		for(int i=x;i<=y-k+1;++i){
			ans=max(ans,dep[LCA(g[i][len],g[i+(k-(1ll<<len))][len])] );
		}
		printf("%d\n",ans);
	}
	return 0;
}
/*
9
1 2 
2 4 
4 6
6 7
2 5
5 9
5 8
1 3

1 3
2 5
6 9
*/
/*
6
5 6
6 1
6 2
2 3
2 4
3
2 5 2
1 4 1
1 6 3


*/
