#include<bits/stdc++.h>
#define ri register int
#define ll long long
#define mkp make_pair
using namespace std;
const int maxn=5e5+7;
int n,q;
vector<int>vec[maxn];
int lg[maxn*3],st[21][maxn*3];
int dep[maxn];
int dfn[maxn],tot;
int st1[21][maxn],st2[21][maxn];
void dfs(int u,int fa){
	dep[u]=dep[fa]+1;
	dfn[u]=++tot;
	st[0][tot]=dep[u];
	for(auto v:vec[u]){
		if(v==fa)continue;
		dfs(v,u);
		st[0][++tot]=dep[u];
	}
}
pair<int,int> query_dfn(int l,int r){
	int k=lg[r-l+1];
	return mkp(min(st1[k][l],st1[k][r-(1<<k)+1]),max(st2[k][l],st2[k][r-(1<<k)+1]));
}
int query(int l,int r){
	int k=lg[r-l+1];
	return min(st[k][l],st[k][r-(1<<k)+1]);
}
signed main(){
	ios::sync_with_stdio(0);
	freopen("query.in","r",stdin);
	freopen("query.out","w",stdout);
	cin>>n;
	for(ri i=1;i<n;i++){
		int u,v;cin>>u>>v;
		vec[u].emplace_back(v);vec[v].emplace_back(u); 
	}
	dfs(1,0);
	for(ri i=1;i<=n;i++)st1[0][i]=st2[0][i]=dfn[i];
	for(ri t=1;1<<t<=n;t++){
		for(ri i=1;i+(1<<t)-1<=n;i++){
			st1[t][i]=min(st1[t-1][i],st1[t-1][i+(1<<t-1)]);
			st2[t][i]=max(st2[t-1][i],st2[t-1][i+(1<<t-1)]);
		}
	}
	for(ri i=2;i<=tot;i++)lg[i]=lg[i>>1]+1;
	cin>>q;
	for(ri t=1;1<<t<=tot;t++){
		for(ri i=1;i+(1<<t)-1<=tot;i++){
			st[t][i]=min(st[t-1][i],st[t-1][i+(1<<t-1)]);
		}
	}
	for(ri i=1;i<=q;i++){
		int l,r,k;cin>>l>>r>>k;
		l=l+k-1;
		int ans=0;
		for(ri j=l;j<=r;j++){
			pair<int,int>ddd=query_dfn(j-k+1,j);
			ans=max(ans,query(ddd.first,ddd.second));
		}
		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

*/
