#include<bits/stdc++.h>
using namespace std;
const int N=1e6+50;
int n;
struct edge{
	int v,nex;
}e[N];
int fir[N],cnt,maxi[N],mini[N],b[N],a[N],lg[N];
void add(int u,int v){
	e[++cnt]=(edge){v,fir[u]},fir[u]=cnt;
}
void dfs(int u,int fa){
	maxi[u]=mini[u]=u;
	for(int i=fir[u];i;i=e[i].nex){
		int v=e[i].v;
		if(v==fa)continue;
		dfs(v,u);
		maxi[u]=max(maxi[u],maxi[v]);
		mini[u]=min(mini[u],mini[v]);
	}
	++b[mini[u]];
	--b[maxi[u]+1];
}
#define lc (u<<1)
#define rc (lc|1)
#define mid (l+r>>1)
#define ls lc,l,mid
#define rs rc,mid+1,r 
int v[N<<2];
void build(int u,int l,int r){
	if(l==r){
		v[u]=a[l];
		return ;
	}
	build(ls);
	build(rs);
	v[u]=min(v[lc],v[rc]);
}
int query(int u,int l,int r,int s,int e){
	if(s<=l&&r<=e)return v[u];
	if(s<=mid&&mid<e)return min(query(ls,s,e),query(rs,s,e));
	if(s<=mid)return query(ls,s,e);
	if(mid<e)return query(rs,s,e); 
}
int main(){
	freopen("query.in","r",stdin);
	freopen("query.out","w",stdout);
	scanf("%d",&n);
	for(int i=1,u,v;i<n;i++){
		scanf("%d%d",&u,&v);
		u=u*2-1,v=v*2-1;
		add(u,v);
		add(v,u);
	}
	dfs(1,1);
	n=n*2-1;
	for(int i=1;i<=n;++i)a[i]=a[i-1]+b[i];
	build(1,1,n);
	int Q;
	scanf("%d",&Q);
	while(Q--){
		int l,r,k;
		scanf("%d%d%d",&l,&r,&k);
		int ans=0;
		for(int i=l;i+k-1<=r;++i)ans=max(ans,query(1,1,n,i*2-1,(i+k-1)*2-1));
		cout<<ans<<"\n";
	}
	return 0; 
} 
/*
三小时没有30分，我在干什么！！？？ 
*/
