#include<bits/stdc++.h>
#define ll long long
#define pb push_back
using namespace std;
const int N=500005,M=20,mod=1e9+7;
int n,dep[N],f[N][M],d[N][M],lg_[N];
vector<int> g[N];
int LCA(int x,int y){
	if(dep[x]<dep[y])swap(x,y);
	for(int i=M-1;i>=0;i--)if(dep[f[x][i]]>=dep[y])x=f[x][i];
	if(x==y)return x;
	for(int i=M-1;i>=0;i--)if(f[x][i]!=f[y][i])x=f[x][i],y=f[y][i];
	return f[x][0];
}
int ask(int x,int y){
	int k=lg_[y-x+1];
	return LCA(d[y][k],d[x+(1<<k)-1][k]);
}
void solve(int x=0,int y=0,int z=0,int ans=0){
	cin>>x>>y>>z;
	for(int i=x;i+z-1<=y;i++)ans=max(ans,dep[ask(i,i+z-1)]);
	cout<<ans<<'\n';
}
void dfs(int u,int fa){
	dep[u]=dep[fa]+1;
	for(int v:g[u])if(v!=fa){
		f[v][0]=u;
		for(int i=1;i<M;i++)f[v][i]=f[f[v][i-1]][i-1];
		dfs(v,u);
	}
}
int main(){
	freopen("query.in","r",stdin);
	freopen("query.out","w",stdout);
	ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
	cin>>n,lg_[0]=-1;
	for(int i=1,x,y;i<n;i++)cin>>x>>y,g[x].pb(y),g[y].pb(x);
	dfs(1,0);
	for(int i=1;i<=n;i++){
		lg_[i]=lg_[i>>1]+1,d[i][0]=i;
		for(int j=1;i-(1<<j)>=0;j++)d[i][j]=LCA(d[i][j-1],d[i-(1<<(j-1))][j-1]);
	}
	int t;cin>>t;
	while(t--)solve();
	return 0;
}
