#include <bits/stdc++.h>
using namespace std;
const int N=5e5;
int n ,q;
int dep[500005] ,dfn[500005] ,cnt;
int dfn_id[500005];
int lca_st[500005][32] ,bit2[2000005];
int pos[2000005][32] ,cur;
int in[500005];
vector<int> e[500005];
void dfs(int u ,int fa){
//	cout << "dfs : " << u << endl;
	dep[u]=dep[fa]+1;
	dfn[u]=++cnt;
	dfn_id[cnt]=u;
	pos[++cur][0]=dfn[u];
	in[dfn[u]]=cur;
	for(auto v:e[u]){
		if(v==fa)continue;
		dfs(v ,u);
		pos[++cur][0]=dfn[u];
	}
}
int lca(int u ,int v){
	u=dfn[u] ,v=dfn[v];
//	cout << u << ' ' << v << endl;
	u=in[u] ,v=in[v];
//	cout << u << ' ' << v << endl;
	if(u>v)swap(u ,v);
	int len=v-u+1 ,T=bit2[len];
//	cout << "debug : " << T << endl;
	return dfn_id[min(pos[u][T] ,pos[v-(1<<T)+1][T])];
}
int lca2(int l ,int r){
	int len=r-l+1 ,T=bit2[len];
	return lca(lca_st[l][T] ,lca_st[r-(1ll<<T)+1][T]);
}
int main(){
	freopen("query.in" ,"r" ,stdin);
	freopen("query.out" ,"w" ,stdout);
	cin.tie(0) ,cout.tie(0) ,ios::sync_with_stdio(false);
	cin >> n;
	bit2[0]=0;
	for(int i=1;i<=N*4;i++){
		bit2[i]=bit2[i-1];
		if((1ll<<(bit2[i]+1))<=i)bit2[i]++;
	}
	for(int i=1;i<n;i++){
		int u ,v;
		cin >> u >> v;
		e[u].push_back(v);
		e[v].push_back(u);
	}
	dfs(1 ,1);
//	for(int i=1;i<=cur;i++)
//		cout << pos[i][0] << ' ';
//	cout << endl;
//	for(int i=1;i<=n;i++)
//		cout << i << " : " << in[i] << endl;
	for(int i=1;i<32;i++)
		for(int j=1;j<=cur;j++)
			pos[j][i]=min(pos[j][i-1] ,pos[min(j+(1ll<<(i-1)) ,(long long)cur)][i-1]);
//	cout << lca(2 ,5) << endl;
	for(int i=1;i<=n;i++)
		lca_st[i][0]=i;
	for(int i=1;i<32;i++)
		for(int j=1;j<=n;j++)
			lca_st[j][i]=lca(lca_st[j][i-1] ,lca_st[min((long long)n ,j+(1ll<<(i-1)))][i-1]);
	cin >> q;
	while(q--){
		int l ,r ,k ,ans=0;
		cin >> l >> r >> k;
		for(int i=l;i+k-1<=r;i++){
			ans=max(ans ,dep[lca2(i ,i+k-1)]);
		}
		cout << ans << endl;
	}
}
