#include<bits/stdc++.h>
using namespace std;
int n,u,v,q,l,r,k;
int LCA[100005][25],DEP[100005];
vector<int> E[100005];
int ans,now;
void dfs(int i,int fa){
	LCA[i][0] = fa;
	DEP[i] = DEP[fa]+1;
	for(int k:E[i]){
		if(k != fa) dfs(k,i);
	}
}
int lca(int x,int y){
	if(DEP[x] < DEP[y])swap(x,y);
	for(int k=20;k>=0;k--){
		if(DEP[LCA[x][k]] >= DEP[y]){
			x = LCA[x][k];
		}
	}
	if(x == y)return y;
	for(int k=20;k>=0;k--){
		if(LCA[x][k] != LCA[y][k]){
			x = LCA[x][k];
			y = LCA[y][k];
		}
	}
	return LCA[y][0];
}
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",&u,&v);
		E[u].push_back(v);
		E[v].push_back(u);
	}
	dfs(1,0);
	for(int k=1;k<=20;k++){
		for(int i=1;i<=n;i++){
			LCA[i][k] = LCA[LCA[i][k-1]][k-1];
		}
	}
	scanf("%d",&q);
	for(int i=1;i<=q;i++){
		scanf("%d%d%d",&l,&r,&k);
		ans = -1;
		for(int s=l;s+k<=r+1;s++){
			now = s;
			for(int j=s+1;j<s+k;j++){
				now = lca(now,j);
			}
			ans = max(ans,DEP[now]);
		}
		printf("%d\n",ans);
	}
	return 0;
}
/*
6
5 6
6 1
6 2
2 3
2 4
3
2 5 2
1 4 1
1 6 3
*/
