#include <bits/stdc++.h>
#define ll long long
using namespace std;
inline ll read(){
	ll s=0,f=1;
	char ch=getchar();
	while(!isdigit(ch)){
		if(ch=='-') f=-1;
		ch=getchar();
	}
	while(isdigit(ch)){
		s=s*10+(ch-'0');
		ch=getchar();
	}
	return s*f;
}
#define vector basic_string
ll n,q,dfn[500010],siz[500010],s[500010][21],tot,lg[500010],dep[500010],f[500010][21];
vector<ll>e[500010];
void dfs(ll u,ll f){
	dfn[u]=++tot,siz[u]=1,dep[u]=dep[f]+1;
	s[dfn[u]][0]=f;
	for(ll v:e[u])
		if(v^f) dfs(v,u),siz[u]+=siz[v];
}
ll g(ll x,ll y){
	return dep[x]<dep[y]?x:y;
}
ll gx(ll x,ll y){
	return dep[x]>dep[y]?x:y;
}
ll query(ll x,ll y){
	if(x==y) return x;
	if((x=dfn[x])>(y=dfn[y])) swap(x,y);
	x++;
	ll len=lg[y-x+1];
	return g(s[x][len],s[y-(1<<len)+1][len]);
}
ll getd(ll l,ll r){
	ll len=lg[r-l+1];
	return query(f[l][len],f[r-(1<<len)+1][len]);
}
int main(){
	freopen("query.in","r",stdin);
	freopen("query.out","w",stdout);
	n=read();
	for(ll i=1,u,v;i<n;i++)
		u=read(),v=read(),e[u]+=v,e[v]+=u;
	q=read();
	dfs(1,0);
	for(ll i=2;i<=n;i++) lg[i]=lg[i>>1]+1;
	for(ll j=1;1<<j<=n;j++)
		for(ll i=1;i+(1<<j)-1<=n;i++)
			s[i][j]=g(s[i][j-1],s[i+(1<<j-1)][j-1]);
	for(ll i=1;i<=n;i++) f[i][0]=i;
	for(ll j=1;1<<j<=n;j++)
		for(ll i=1;i+(1<<j)-1<=n;i++)
			f[i][j]=query(f[i][j-1],f[i+(1<<j-1)][j-1]);
	while(q--){
		ll l=read(),r=read(),k=read(),ans=0;
		for(ll i=l;i+k-1<=r;i++) ans=gx(ans,getd(i,i+k-1));
		printf("%lld\n",dep[ans]);
	}
	return 0;
}

