#include <bits/stdc++.h>
using namespace std;
const int N=500005;
int n,q,dep[N],siz[N],ans,l,r,k;
vector <int> g[N];
void dfs0(int u,int fa){
	dep[u]=dep[fa]+1;
	for(int i=0;i<g[u].size();i++){
		int v=g[u][i];
		if(v==fa)continue;
		dfs0(v,u);
	} 
}
void dfs(int u,int fa,int l,int r){
	siz[u]=(u>=l&&u<=r);
	for(int i=0;i<g[u].size();i++){
		int v=g[u][i];
		if(v==fa)continue;
		dfs(v,u,l,r);
		siz[u]+=siz[v];
	}
	if(siz[u]>=k){
		ans=max(ans,dep[u]);
	}
}
signed 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=2;i<=n;i++){
		int x,y;
		cin>>x>>y;
		g[x].push_back(y);
		g[y].push_back(x);
	}
	dfs0(1,0);
	cin>>q;
	if(n<=500&&q<=500){
		for(int i=1;i<=q;i++){
			cin>>l>>r>>k;
			ans=1;
			for(int j=l;j+k-1<=r;j++){
				dfs(1,0,j,j+k-1);
			}
			cout<<ans<<" \n";
		}
		return 0;
	}
} 
