#include<bits/stdc++.h>
using namespace std;
signed main(){
	ios::sync_with_stdio(false);
	cin.tie(0); cout.tie(0);
	freopen("query.in","r",stdin);
	freopen("query.out","w",stdout);
	int n; cin>>n;
	vector<int> lg(n+1,0);
	for(int i=2;i<=n;i++) lg[i]=lg[i>>1]+1;
	vector<vector<int>> g(n+1);
	vector<vector<int>> fa(n+1,vector<int>(lg[n]+1,0));
	vector<vector<int>> st(n+1,vector<int>(lg[n]+1,0));
	vector<int> dep(n+1,0);
	for(int i=1;i<n;i++){
		int u,v; cin>>u>>v;
		g[u].push_back(v);
		g[v].push_back(u);
	}
	auto dfs=[&](auto self,int u,int pre)->void{
		dep[u]=dep[pre]+1; fa[u][0]=pre;
		for(int i=1;i<=lg[n]+1;i++) fa[u][i]=fa[fa[u][i-1]][i-1];
		for(int v:g[u]){
			if(v==pre) continue;
			self(self,v,u);
		}
	};
	dfs(dfs,1,0);
	auto LCA=[&](int u,int v)->int{
		if(dep[u]<dep[v]) swap(u,v);
		for(int i=lg[n]+1;i>=0;i--){
			if(dep[fa[u][i]]>=dep[v]) u=fa[u][i];
		}
		if(u==v) return u;
		for(int i=lg[n]+1;i>=0;i--){
			if(fa[u][i]!=fa[v][i]){
				u=fa[u][i]; v=fa[v][i];
			}
		}
		return fa[u][0];
	};
	for(int i=1;i<=n;i++) st[i][0]=i;
	for(int j=1;j<=lg[n];j++){
		for(int i=1;i+(1<<j)-1<=n;i++){
			st[i][j]=LCA(st[i][j-1],st[i+(1<<(j-1))][j-1]);
		}
	}
	int q; cin>>q;
	while(q--){
		int l,r,k; cin>>l>>r>>k;
		int ans=0;
		for(int i=l;i+k-1<=r;i++){
			ans=max(ans,dep[LCA(st[i][lg[k]],st[i+k-(1<<lg[k])][lg[k]])]);
		}
		cout<<ans<<"\n";
	}
	return 0;
}
