#include<cstdio>
#include<algorithm>
const int N=5e3+5,M=1e4+5,inf=1e9;
int n,q,h[N],v[M],nxt[M],tot,dep[N],fa[N][15],lg[N],lc[N][N];
void add(int x,int y){v[++tot]=y; nxt[tot]=h[x]; h[x]=tot;}
void dfs(int x,int fat){
	dep[x]=dep[fat]+1; fa[x][0]=fat;
	for(int i=1;i<=lg[dep[x]];++i)
		fa[x][i]=fa[fa[x][i-1]][i-1];
	for(int i=h[x],y;i;i=nxt[i]){
		y=v[i]; if(y==fat) continue;
		dfs(y,x);
	}
}
int lca(int x,int y){
	if(dep[x]<dep[y]){int tmp=x; x=y; y=tmp;}
	for(int i=lg[dep[x]];i>=0;--i)
		if(dep[fa[x][i]]>=dep[y]) x=fa[x][i];
	if(x==y) return x;
	for(int i=lg[dep[x]];i>=0;--i)
		if(fa[x][i]!=fa[y][i])
			x=fa[x][i],y=fa[y][i];
	return fa[x][0];
}
int 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);
		add(x,y); add(y,x);
	}
	lg[0]=-1; for(int i=1;i<=n;++i) lg[i]=lg[i>>1]+1;
	dfs(1,0);
	for(int i=1;i<=n;++i){
		lc[i][i]=i;
		for(int j=i+1;j<=n;++j)
			if(lc[i][j-1]==1) lc[i][j]=1;
			else lc[i][j]=lca(lc[i][j-1],j);
	}
	scanf("%d",&q);
	for(int i=1,l,r,k,ans;i<=q;++i){
		scanf("%d%d%d",&l,&r,&k); ans=0;
		for(int j=l;j+k-1<=r;++j)
			ans=std::max(ans,dep[lc[j][j+k-1]]);
		printf("%d\n",ans);
	}
	return 0;
}
