#include<bits/stdc++.h>
using namespace std;
int n,u,v,q,l,r,k,lac,d[500005],f[500005];
int b[500005],maxnd,ans;
vector<int>G[500005];
void fd(){
	queue<int>q;
	d[1]=1,f[1]=-1;
	q.push(1);
	while(!q.empty()){
		int p=q.front();
		q.pop();
		maxnd=max(maxnd,d[p]);
		for(auto op:G[p]){
			if(d[op]==0){
				d[op]=d[p]+1,f[op]=p;
				q.push(op);
			}
		}
	}
}
int lca(int a,int b){
	while(d[f[a]]>d[f[b]])a=f[a];
	while(d[f[b]]>d[f[a]])b=f[b];
	while(a!=b)a=f[a],b=f[b];
	return a;
}
int main(){
	freopen("query.in","r",stdin);
	freopen("query.out","w",stdout);
	ios::sync_with_stdio(false);
	cin.tie(0);
	cin>>n;
	for(int x=1;x<n;x++){
		cin>>u>>v;
		G[u].push_back(v);
		G[v].push_back(u);
	}
	fd();
	if(maxnd==n){
		cin>>q;
		for(int x=1;x<=q;x++){
			cin>>l>>r>>k;
			for(int y=l;y<=r;y++)b[y]=d[l];
			sort(b+l,b+r+1);
			cout<<b[r-k+1]<<"\n";
		}
		return 0;
	}
	cin>>q;
	for(int x=1;x<=q;x++){
		cin>>l>>r>>k;
		ans=0;
		for(int y=l;y+k-1<=r;y++){
			if(k==1)ans=max(ans,d[y]);
			else{
				lac=lca(y,y+1);
				for(int z=y+2;z<=y+k-1;z++){
					lac=lca(lac,z);
				}
				ans=max(d[lac],ans);
			}
		}
		cout<<ans<<"\n";
	}
	return 0;
}
