#include<bits/stdc++.h>
#define x0 x_0
#define x1 x_1
#define y0 y_0
#define y1 y_1
#define yn y_n
#define j0 j_0
#define j1 j_1
#define d0 d_0
#define d1 d_1
#define k0 k_0
#define k1 k_1
#define LL long long
#define LD long double
using namespace std;
int n,q,dep[500010],par[500010][19],son[500010],st[500010][19],logg[500010];
vector<int> G[500010];
void dfs(int x,int fa){
	dep[x]=dep[fa]+1,par[x][0]=fa;
	for(int i=1;i<=18;++i) par[x][i]=par[par[x][i-1]][i-1];
	for(int i=0;i<(int)G[x].size();++i){
		int u=G[x][i];
		if(u==fa) continue;
		++son[x],dfs(u,x);
	}
	return ;
}
int get_LCA(int u,int v){
	if(dep[u]<dep[v]) swap(u,v);
	int cha=dep[u]-dep[v];
	for(int i=18;i>=0;--i)
		if(cha&(1<<i)) u=par[u][i];
	if(u==v) return u;
	for(int i=18;i>=0;--i)
		if(par[u][i]^par[v][i]) u=par[u][i],v=par[v][i];
	return par[u][0];
}
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;i<n;++i){
		int u,v;
		cin>>u>>v;
		G[u].push_back(v);
		G[v].push_back(u);
	}
	dfs(1,0);
	for(int i=1;i<=n;++i) st[i][0]=i;
	for(int j=1;j<=18;++j){
		for(int i=1;i+(1<<j)-1<=n;++i){
			st[i][j]=get_LCA(st[i][j-1],st[i+(1<<(j-1))][j-1]);
		}
	}
	for(int i=2;i<=n;++i) logg[i]=logg[i>>1]+1;
	cin>>q;
	while(q--){
		int l,r,k;
		cin>>l>>r>>k;
		int ans=-1000000000,x=logg[k];
		for(int i=l;i+k-1<=r;++i){
			ans=max(ans,dep[get_LCA(st[i][x],st[(i+k-1)-(1<<x)+1][x])]);
		}
		cout<<ans<<"\n";
	}
	return 0;
}
/*
6
5 6
6 1
6 2
2 3
2 4
3
2 5 2
1 4 1
1 6 3
*/
