#include<bits/stdc++.h>
using namespace std;
const int N=6e5+10,LO=18;
int n,q;
vector<int> to[N];
int fa[N],dep[N],cntdfn,dfn[N],aa[N],dy[N],mind[N][LO+3],mini[N][LO+3];
int lcaa[N][LO];
void dfs(int k,int faa){
	fa[k]=faa;
	dep[k]=dep[faa]+1;
	for(auto i:to[k])
		if(i!=faa)
			dfs(i,k);
	dfn[k]=++cntdfn;
}int lca(int u,int v){
	if(u==v)return u;
	u=dy[u],v=dy[v];
	if(u>v)swap(u,v);
	v--;
	int len=__lg(v-u+1);
//	cout<<u<<' '<<v<<endl;
	int res;
	if(mind[u][len]<mind[v-(1<<len)+1][len])res=mini[u][len];
	else res=mini[v-(1<<len)+1][len];
	return fa[res];
}int lca_(int u,int v){
	int len=__lg(v-u+1);
	return lca(lcaa[u][len],lcaa[v-(1<<len)+1][len]);
}
int main(){
	freopen("query.in","r",stdin);
	freopen("query.out","w",stdout);
	ios::sync_with_stdio(false);cin.tie(0),cout.tie(0);
	cin>>n;
	for(int i=1,u,v;i<n;i++)
		cin>>u>>v,to[u].push_back(v),to[v].push_back(u);
	dfs(1,0);
	for(int i=1;i<=n;i++)
		aa[i]=i;
	sort(aa+1,aa+n+1,[&](int q,int p){
		return dfn[q]<dfn[p];
	});
	for(int i=1;i<=n;i++)
		dy[aa[i]]=i;
	for(int i=1;i<=n;i++)
		mind[i][0]=dep[aa[i]],mini[i][0]=aa[i];
//	for(int i=1;i<=n;i++)
//		cout<<aa[i]<<' '<<mind[i][0]<<' '<<mini[i][0]<<endl;
	for(int o=1;o<=LO;o++)
		for(int i=1;i<=n-(1<<o)+1;i++)
			if(mind[i][o-1]<mind[i+(1<<(o-1))][o-1])
				mind[i][o]=mind[i][o-1],mini[i][o]=mini[i][o-1];
			else mind[i][o]=mind[i+(1<<(o-1))][o-1],mini[i][o]=mini[i+(1<<(o-1))][o-1];
	for(int i=1;i<=n;i++)
		lcaa[i][0]=i;
	for(int o=1;o<=LO;o++)
		for(int i=1;i<=n-(1<<o)+1;i++)
			lcaa[i][o]=lca(lcaa[i][o-1],lcaa[i+(1<<(o-1))][o-1]);
	
	cin>>q;
//	while(q--){
//		int l,r;cin>>l>>r;cout<<lca(l,r)<<endl;
//	}
//	cout<<lca(2,4)<<endl;return 0;
	while(q--){
		int l,r,k,ans=0,tmp;cin>>l>>r>>k;
		for(int i=l;i<=r-k+1;i++)
			tmp=lca_(i,i+k-1),ans=max(ans,dep[tmp]);
		cout<<ans<<'\n';
	}
	return 0;
} 
