#include<bits/stdc++.h>
using namespace std;
const int N=5e5+1;
int n,m,x,y,k,f[N][21],d[N],gl[N],h[N][21],r;
vector<int>g[N];
void dfs(int u,int z){
	d[u]=d[z]+1;f[u][0]=z;
	for(int i=1; i<21; i++)f[u][i]=f[f[u][i-1]][i-1];
	for(int i=0; i<g[u].size(); i++){
		int v=g[u][i];
		if(v!=z)dfs(v,u);
	}
}
int lca(int a,int b){
	if(d[a]<d[b])swap(a,b);
	for(int i=20; i>=0; i--)if(d[f[a][i]]>=d[b])a=f[a][i];
	if(a==b)return a;
	for(int i=20; i>=0; i--)if(f[a][i]!=f[b][i])a=f[a][i],b=f[b][i];
	return f[a][0];
}
int gel(int l,int r){
	int c=gl[r-l+1];
	return lca(h[l][c],h[r-(1<<c)+1][c]);
}
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;
	for(int i=1; i<=n; i++){
		h[i][0]=i;
		if(i>1)gl[i]=gl[i/2]+1;
	}
	for(int i=1; i<n; i++){
		cin>>x>>y;
		g[x].push_back(y);
		g[y].push_back(x);
	}
	dfs(1,1);
	for(int j=1; (1<<j)<=n; j++){
		for(int i=1; i+(1<<j)-1<=n; i++){
			h[i][j]=lca(h[i][j-1],h[i+(1<<j-1)][j-1]);
		}
	}
	cin>>m;
	while(m--){
		cin>>x>>y>>k;r=0;
		for(int i=x+k-1; i<=y; i++)r=max(d[gel(i-k+1,i)],r);
		cout<<r<<"\n";
	}
	return 0;
}
