#include<bits/stdc++.h>
const int MAXN=5e5+5;
int n;
int d[MAXN];
std::vector <int> edge[MAXN];
int depth[MAXN],fa[MAXN][25];
inline void dfs(int u,int father){
	depth[u]=depth[father]+1,fa[u][0]=father;
	for(int i=1;i<=20;i++) fa[u][i]=fa[fa[u][i-1]][i-1];
	for(auto v:edge[u]){
		if(v==father) continue;
		dfs(v,u);
	}
}
inline int LCA(int x,int y){
	if(depth[x]<depth[y]) std::swap(x,y);
	for(int i=20;i>=0;i--)
		if(depth[fa[x][i]]>=depth[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];
}
signed 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);
		edge[u].push_back(v),edge[v].push_back(u);
	}
	dfs(1,0);
	int q;scanf("%d",&q);
	while(q--){
		int l,r,k;scanf("%d%d%d",&l,&r,&k);
		int ans(0);
		for(int i=l;i<=r;i++){
			if(i+k-1>r) continue;
			int lca=i;
			for(int j=i+1;j<=i+k-1;j++) lca=LCA(lca,j);
			ans=std::max(ans,depth[lca]);
		}
		printf("%d\n",ans);
	}
}
