#include<bits/stdc++.h>
using namespace std;
int n,q,h[500010],to[1000010],nxt[1000010],cnt;
int siz[500010],dep[500010];
int fa[500010],lt[500010];
int f[500010][23],lg[500010];
void inst(int x,int y){
	to[++cnt]=y,nxt[cnt]=h[x],h[x]=cnt;
}
void dfs0(int x,int f){
	siz[x]=1,dep[x]=dep[f]+1,fa[x]=f;
	for(int i=h[x];i;i=nxt[i]){
		int y=to[i];
		if(y!=f)
			dfs0(y,x),siz[x]+=siz[y];
	}
}
void dfs1(int x,int fa,int t){
	lt[x]=t;
	int p=0;
	for(int i=h[x];i;i=nxt[i]){
		int y=to[i];
		if(y!=fa&&siz[p]<siz[y])
			p=y;
	}
	if(p)dfs1(p,x,t);
	for(int i=h[x];i;i=nxt[i]){
		int y=to[i];
		if(y!=fa&&y!=p)
			dfs1(y,x,y);
	}
}
int Lca(int x,int y){
	while(lt[x]!=lt[y]){
		if(dep[lt[x]]<dep[lt[y]])swap(x,y);
		x=fa[lt[x]];
	}
	if(dep[x]>dep[y])swap(x,y);
	return x;
}
int qry(int l,int r){
	int k=lg[r-l+1];
	return Lca(f[l][k],f[r-(1<<k)+1][k]);
}
signed main(){
	freopen("query.in","r",stdin);
	freopen("query.out","w",stdout);
	scanf("%d",&n);
	for(int i=1,x,y;i<n;i++){
		scanf("%d%d",&x,&y);
		inst(x,y),inst(y,x);
	}
	dfs0(1,0),dfs1(1,0,1);
	lg[0]=-1;
	for(int i=1;i<=n;i++)
		f[i][0]=i,lg[i]=lg[i/2]+1;
	for(int j=1;j<=20;j++)
		for(int i=1;i+(1<<j)-1<=n;i++)
			f[i][j]=Lca(f[i][j-1],f[i+(1<<(j-1))][j-1]);
	scanf("%d",&q);
	int l,r,k;
	while(q--){
		scanf("%d%d%d",&l,&r,&k);
		int ans=0;
		for(int i=l+k-1;i<=r;i++)
			ans=max(ans,dep[qry(i-k+1,i)]);
		printf("%d\n",ans);
	}
	return 0;
}
