#include<iostream>
#include<vector>
#define ll long long
#define endl '\n'
using namespace std;
const int maxn=5e5+10;
vector<int>e[maxn];
int f[maxn][21],dep[maxn];
void dfs(int u,int fa){
	dep[u]=dep[fa]+1;
	for(int v:e[u]){
		if(v==fa)continue;
		f[v][0]=u;
		for(int i=1;i<=20;++i)f[v][i]=f[f[v][i-1]][i-1];
		dfs(v,u);
	}
}
int lca(int x,int y){
	if(dep[x]<dep[y])swap(x,y);
	for(int i=20;i>=0;--i){
		if(dep[f[x][i]]>=dep[y])x=f[x][i];
	}
	if(x==y)return y;
	for(int i=20;i>=0;--i){
		if(f[x][i]!=f[y][i]){
			x=f[x][i],y=f[y][i];
		}
	}
	return f[x][0];
}
signed main(){
	ios::sync_with_stdio(0);
	cin.tie(0),cout.tie(0);
	freopen("query.in","r",stdin);
	freopen("query.out","w",stdout);
	int n;
	cin>>n;
	for(int i=1;i<n;++i){
		int u,v;
		cin>>u>>v;
		e[u].push_back(v);
		e[v].push_back(u);
	}
	dfs(1,0);
	int q;
	cin>>q;
	while(q--){
		int l,r,k;
		cin>>l>>r>>k;
		int ans=-1;
		if(k!=1){
			for(int i=l;i+k-1<=r;++i){
				int o=lca(i,i+1);
				for(int tmp=i+2;tmp<=i+k-1;++tmp){
					o=lca(o,tmp);
				}
				ans=max(ans,dep[o]);
			}
		}else{
			for(int i=l;i<=r;++i)ans=max(ans,dep[i]);
		}
		cout<<ans<<endl;
	}
	return 0;
}
/*
6
5 6
6 1
6 2
2 3
2 4
3
2 5 2
1 4 1
1 6 3

*/
