#include<bits/stdc++.h>
using namespace std;
#define int long long 
const int N=5e5+10;
int rule[N<<1],s[N<<1][40],deep[N],id;
int head[N],to[N<<1],nxt[N<<1],idx;
int st[N],ed[N];
int s1[N],s2[N],l1,r1,l2,r2;
int n,ans,t,q;
inline void add(int u,int v){
	to[idx]=v;
	nxt[idx]=head[u];
	head[u]=idx++;
}
void dfs(int u,int fa){
	deep[u]=deep[fa]+1;
	rule[++id]=u;
	for(int i=head[u];~i;i=nxt[i]){
		int v=to[i];
		if(v==fa)continue;
		dfs(v,u);
		rule[++id]=u;
	}
}
inline get_len(int x){
	int res=0;
	while(x){
		res++;
		x>>=1;
	}
	return res;
}
inline void build(){
	for(int i=1;i<=2*n-1;i++)s[i][0]=rule[i];
	for(int j=1;j<=get_len(2*n-1);j++){
//		cerr<<"j:"<<j<<endl;
		for(int i=1;i<=2*n-2-(1ll<<j-1);i++){
//			cerr<<i<<" ";
			if(deep[s[i][j-1]]<deep[s[i+(1<<j-1)][j-1]])s[i][j]=s[i][j-1];
			else s[i][j]=s[i+(1<<j-1)][j-1];
		}
//		cerr<<"\n";
		for(int i=2*n-2-(1ll<<j-1)+1;i<=2*n-2;i++){
//			cerr<<i<<" ";
			s[i][j]=s[i][j-1];
		}
//		cerr<<"\n";
	}
}
inline int query(int l,int r){
//	cerr<<"query:"<<l<<" "<<r<<endl;
	int len=r-l+1,res=0;
	int ll=get_len(len)-1,rr=r-(1<<ll)+1;
//	cerr<<"l:"<<ll<<" r:"<<rr<<endl;
//	cerr<<"ll:"<<s[l][ll]<<" rr:"<<s[rr][ll]<<endl;
	if(deep[s[l][ll]]<deep[s[rr][ll]])return s[l][ll];
	else return s[rr][ll];
}
inline int read(){
	int res=0;bool s=0;char c=getchar();
	for(;!isdigit(c);c=getchar())if(c=='-')s=1;
	for(;isdigit(c);c=getchar())res=(res<<3)+(res<<1)+(c^48);
	return s?-res:res;
}
signed main(){
	freopen("query.in","r",stdin);
	freopen("query.out","w",stdout);
	n=read();
	for(int i=1;i<=n;i++)head[i]=-1;
	for(int i=1;i<n;i++){
		int u,v;
		u=read();v=read();
		add(u,v);add(v,u);
	}
	dfs(1,1);
//	cerr<<"dfs_ed\n";
	for(int i=1;i<=n;i++)st[i]=0x3f3f3f3f3f;
	for(int i=1;i<=2*n-1;i++){
//		cerr<<rule[i]<<" ";
		st[rule[i]]=min(st[rule[i]],i);
		ed[rule[i]]=max(ed[rule[i]],i);
	}
//	cerr<<"\n";
//	for(int i=1;i<=2*n-1;i++){
//		cerr<<deep[rule[i]]<<" ";
//	}
//	cerr<<endl;
	
//	cerr<<"get_range_end\n";
	build();
//	cerr<<"build_end\n";
	q=read();
	while(q--){
		int l,r,k,ans=0;
		l=read();r=read();k=read();
//		cerr<<l<<" "<<r<<endl;
		l1=1;r1=0;l2=1;r2=0;
		
		for(int i=l;i<=l+k-2;i++){
			while(r1-l1+1&&st[s1[r1]]>=st[i])r1--;
			while(r2-l2+1&&ed[s2[r2]]<=ed[i])r2--;
			s1[++r1]=i;
			s2[++r2]=i;
		}
//		cerr<<"pre_end\n";
		for(int i=l+k-1;i<=r;i++){
//			cerr<<"i:"<<i<<endl;
			while(r1-l1+1&&st[s1[r1]]>=st[i])r1--;
			while(r2-l2+1&&ed[s2[r2]]<=ed[i])r2--;
			s1[++r1]=i;
			s2[++r2]=i;
			while(l1<=r1&&s1[l1]<i-k+1)l1++;
//			cerr<<"l1"<<l1<<'\n';
			while(l2<=r2&&s2[l2]<i-k+1)l2++;
//			cerr<<"l2"<<l2<<'\n';
//			cerr<<"LCA:"<<query(st[s1[l1]],ed[s2[l2]])<<endl;
			ans=max(ans,deep[query(st[s1[l1]],ed[s2[l2]])]);
		}
		printf("%lld\n",ans);
	}
	return 0;
}
