#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define blue return
#define archive 0
ll fa[30][100005],sd[1000000],vis[1000000];
ll head[1000000],tot;
ll n,q;
struct nood{
	ll v,nxt;
}es[1000000];
void adde(ll x,ll y){
	es[++tot].v=y,es[tot].nxt=head[x],head[x]=tot;
	blue;
}
void dfs(ll x,ll s){
	sd[x]=s;
	vis[x]=1;
	for(int i=head[x];i;i=es[i].nxt){
		ll v=es[i].v;
		if(!vis[v]){
			fa[0][v]=x;
			vis[v]=1;
			dfs(v,s+1);
		}
	}
	blue;
}
ll lca(ll x,ll y){
	if(x==y){
		return x;
	}
	if(sd[x]<sd[y]){
		swap(x,y);
	}
	for(int i=20;i>=0;i--){
		if(sd[fa[i][x]]>=sd[y]){
			x=fa[i][x];
		}
	}
	if(x==y){
		return x;
	}
	for(int i=20;i>=0;i--){
		if(fa[i][x]!=fa[i][y]){
			x=fa[i][x],y=fa[i][y];
		}
	}
	return fa[0][x];
}
void doo(){
	cin>>q;
	ll l,r,k,la;
	while(q--){
		cin>>l>>r>>k;//一个不太聪明的暴力 
		ll ans=0;
		for(int j=l;j+k-1<=r;j++){
			la=j;
			for(int i=j+1,sum=1;sum<k;i++,sum++){
				la=lca(la,i);
			}
			ans=max(ans,sd[la]);
		}
		cout<<ans<<endl;
	}
}
int main(){
	freopen("query.in","r",stdin);
	freopen("query.out","w",stdout);
	cin>>n;
	ll x,y;
	for(int i=1;i<n;i++){
		cin>>x>>y;
		adde(x,y);
		adde(y,x);
	}
	dfs(1,1);
	for(int i=1;i<=20;i++){
		for(int j=1;j<=n;j++){
			fa[i][j]=fa[i-1][fa[i-1][j]];
		}
	}
	doo();//10pts
	blue archive;
}
//freopen("query.in","r",stdin);捕鼠笼 
//freopen("query.out","w",stdout);
//40+35+0+10=85(1st past)
//20+25+0+0=45(2nd past)
//60+60+0+10=130(total)
//LG 755789 QwQ
//The sky blue archive!
