#include <bits/stdc++.h>
using namespace std;
int T,n;
vector<int> g[500010];
int dep[500010];
int f[25][500010],lg[500010],tim=0,dfn[500010];
bool A=false;
void dfs(int u,int fa){
	dep[u]=dep[fa]+1;
	dfn[u]=++tim;
	f[0][u]=fa;
	if(dep[u]==n) A=true;
	for(auto v:g[u]){
		if(v==fa) continue;
		dfs(v,u);
	}
}
deque<int> q,p;
int lca(int x,int y){
	if(dep[x]<dep[y]) swap(x,y);
	for(int j=lg[dep[x]];j>=0;j--){
		if(dep[f[j][x]]>=dep[y]) x=f[j][x];
	}
	if(x==y) return x;
	for(int j=lg[dep[x]];j>=0;j--){
		if(f[j][x]!=f[j][y]) x=f[j][x],y=f[j][y];
	}
	return f[0][x];
}
int tot=0,tmp[500010];
signed 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;i<n;i++){
		int aa,bb;
		cin>>aa>>bb;
		g[aa].push_back(bb);
		g[bb].push_back(aa);
	}
	dfs(1,0);
	lg[0]=-1;
	for(int i=1;i<=n;i++) lg[i]=lg[i>>1]+1;
	for(int j=1;j<=lg[n];j++){
		for(int i=1;i<=n;i++){
			f[j][i]=f[j-1][f[j-1][i]];
		}
	}
	cin>>T;
	while(T--){
		int l,r,k;
		cin>>l>>r>>k;
		int ans=0;
		while(!q.empty()) q.pop_back();
		while(!p.empty()) p.pop_back();
		for(int i=l;i<=r;i++){
			if(q.empty()) q.push_back(i);
			else{
				while(!q.empty()&&i-q.front()+1>k) q.pop_front();
				while(!q.empty()&&dfn[i]<dfn[q.back()]) q.pop_back();
				q.push_back(i);
			}
			if(p.empty()) p.push_back(i);
			else{
				while(!p.empty()&&i-p.front()+1>k) p.pop_front();
				while(!p.empty()&&dfn[i]>dfn[p.back()]) p.pop_back();
				p.push_back(i);
			}
			if(i>=l+k-1) ans=max(ans,dep[lca(q.front(),p.front())]);
		}
		cout<<ans<<'\n';
	}
	return 0;
}
/*
1
2 1 3
1 1

1
2 1 3
2 1

3
2 1 2
1 1
2 2 2
1 1
2 2
2 2 2
1 1
1 2

*/
