#include<bits/stdc++.h>
#define ll long long
using namespace std;
ll n,q;
struct Edge{
	ll to,next;
}edg[1000010];
ll tol=0,head[500010];
void add(ll u,ll v){
	tol++;
	edg[tol].to=v;
	edg[tol].next=head[u];
	head[u]=tol;
}
ll deep[500010];
ll f[500010][30];
void dfs(ll u,ll fa){
	deep[u]=deep[fa]+1;
	f[u][0]=fa;
	for(ll i=1;i<=log2(deep[u]);i++){
		f[u][i]=f[f[u][i-1]][i-1];
	}
	for(ll i=head[u];i;i=edg[i].next){
		ll v=edg[i].to;
		if(v==fa) continue;
		dfs(v,u);
	}
} 
ll lca(ll u,ll v){
	if(deep[u]<deep[v]) swap(u,v);
	while(deep[u]>deep[v]){
		ll hi=log2(deep[u]-deep[v]);
		u=f[u][hi];
	}
	if(u==v) return u;
	for(ll i=log2(deep[u]);i>=0;i--){
		if(f[u][i]!=f[v][i]){
			u=f[u][i];
			v=f[v][i];
		}
	}
	return f[u][0];
}
int main(){
	freopen("query.in","r",stdin);
	freopen("query.out","w",stdout);
	scanf("%lld",&n);
	for(ll i=1;i<n;i++){
		ll u,v;
		scanf("%lld%lld",&u,&v);
		add(u,v);
		add(v,u);
	}
	dfs(1,0);
	scanf("%lld",&q);
	ll ans=0;
	while(q--){
		ll l,r,k;
		ans=0;
		scanf("%lld%lld%lld",&l,&r,&k);
		for(ll len=k;len<=r-l+1;len++){
			for(ll x=l;x+len-1<=r;x++){
				ll y=x+len-1;
				ans=max(ans,deep[lca(x,y)]);
			}
		}
		printf("%lld\n",ans);
	}
	return 0;
}

