#include<bits/stdc++.h>
using namespace std;
int cnt,n,q;
struct edge{
	int to,nextt;
}e[1000010];
int fir[500010],fa[500010][21],deep[500100],s[500010];
void add(int u,int v){
	e[++cnt].to=v,e[cnt].nextt=fir[u],fir[u]=cnt;
}
void dfs(int u,int father){
	fa[u][0]=father;
	for(int i=1;i<=20;i++)
		fa[u][i]=fa[fa[u][i-1]][i-1];
	deep[u]=deep[father]+1;
	for(int i=fir[u];i;i=e[i].nextt){
		int v=e[i].to;
		if(v==father)continue;
		dfs(v,u);
	}
}
bool cmp(int ma,int mi){
	return deep[ma]<deep[mi];
}
int lca(int x,int y){
	if(deep[x]<deep[y])swap(x,y);
//	printf("%d %d\n",deep[x],deep[y]);
	for(int i=20;i>=0;i--)
		if(deep[fa[x][i]]>=deep[y])
			x=fa[x][i];
	if(x==y)return x;
	for(int i=20;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;i<n;i++){
		int u,v;
		scanf("%d%d",&u,&v);
		add(u,v);
		add(v,u);
	}
	cnt=0;
	dfs(1,0);
	scanf("%d",&q);
///*
	while(q--){
		int l,r,k,ans=0;
		scanf("%d%d%d",&l,&r,&k);
		for(int i=l;i+k-1<=r;i++){
			int res=i;
			for(int j=i+1;j<=i+k-1;j++)
				res=lca(res,j);
			if(deep[res]>deep[ans])ans=res;
		}
		printf("%d\n",deep[ans]);
	}
//*/

//printf("%d",lca(2,3));
	return 0;
}
