#include<bits/stdc++.h>
using namespace std;
#define int long long
#define L(i,l,r) for(int i=l;i<=r;i++)
#define R(i,r,l) for(int i=r;i>=l;i--)

const int N=5e5+10;

int n,q,anc[N][20],depth[N];
vector<int> G[N];
void dfs1(int u,int fa){
//	cerr<<"sdnfjkl\n"; 
	depth[u]=depth[fa]+1;
	anc[u][0]=fa;
	for(auto v:G[u]){
		if(v==fa) continue;
		dfs1(v,u);
	}
}
void init(){
//	cerr<<"sdnfjkl\n"; 
	L(j,1,18){
		L(i,1,n){
			anc[i][j]=anc[anc[i][j-1]][j-1];
		}
	}
}
int lca(int a,int b){
	if(a==b) return a;
	if(depth[a]<=depth[b]) swap(a,b);
	R(i,18,0){
		if(depth[anc[a][i]]>=depth[b]) a=anc[a][i];
	}
	if(a==b) return a;
	R(i,18,0){
		if(anc[a][i]!=anc[b][i]){
			a=anc[a][i]; b=anc[b][i];
		}
	}
	return anc[a][0];
}
void solve(){
	cin>>n;
	L(i,1,n-1){
		int u,v;
		cin>>u>>v;
		G[u].push_back(v);
		G[v].push_back(u);
	}
	dfs1(1,0);
	init(); 
	cin>>q;
	while(q--){
		int l,r,k;
		cin>>l>>r>>k;
		int lst=l;
		int ans=0;
		L(i,l,r-k+1){
			int lst=i;
			L(j,i+1,i+k-1){
				lst=lca(lst,j);
			}
			ans=max(ans,depth[lst]);
		}
		cout<<ans<<'\n';
	}
}
signed main(){
	freopen("query.in","r",stdin);
	freopen("query.out","w",stdout);
	ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	solve();
	return 0;
}
/*
6
5 6
6 1
6 2
2 3
2 4
3
2 5 2
1 4 1
1 6 3
*/

