#include <iostream>
using namespace std;
typedef long long ll;
const ll maxn = 5e5+10,maxlg=20;
ll hed[maxn],cnt_t;
pair<ll,ll> edg[maxn<<2];
void add_edg(ll u,ll v){
	edg[++cnt_t]=make_pair(v,hed[u]);
	hed[u]=cnt_t;
}

ll fa[maxn][maxlg],dep[maxn];
void dfs(ll p,ll f){
	fa[p][0]=f;
	dep[p]=dep[f]+1;
	for(ll i=1;(1<<i)<=dep[p];i++){
		fa[p][i]=fa[fa[p][i-1]][i-1];
	}
	for(ll i=hed[p];i;i=edg[i].second){
		if(edg[i].first!=f) dfs(edg[i].first,p);
	}
} 
ll LCA(ll x,ll y){
	if(dep[x]<dep[y]) swap(x,y);
	for(ll i=maxlg-1;i>=0;i--) if(dep[x]-(1<<i)>=dep[y]) x=fa[x][i];
	if(x==y) return x;
	for(ll i=maxlg-1;i>=0;i--){
		if(fa[x][i]!=fa[y][i]){
			x=fa[x][i];
			y=fa[y][i];
		}
	}
	return fa[x][0];
}
ll n,q;
int main(){
	freopen("query.in","r",stdin);
	freopen("query.out","w",stdout);
	cin>>n;
	for(ll i=1;i<n;i++){
		ll u,v;
		cin>>u>>v;
		add_edg(u,v);
		add_edg(v,u);
	}
	dfs(1,0);
	cin>>q;
	while(q--){
		ll a,b,c;
		cin>>a>>b>>c;
		ll ans = 0;
		for(ll i=a;i+c-1<=b;i++){
			ll x=LCA(i,i+c-1);
			if(dep[x]>=dep[ans]) ans=x;
		}
		cout<<dep[ans]<<endl;
	}
	return 0;
}
