#include<iostream>
#include<cstdio>
#include<string>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<vector>
using namespace std;
const int N=1e6+86;
vector<int> a[N];
int t,q;
int u,v,n;
int fa[N],dp[N],l[N];
int ans;
int main(){
	freopen("query.in","r",stdin);
	freopen("query.out","w",stdout);	
	scanf("%d",&n);
	for(int i=1;i<n;i++){
		scanf("%d%d",&u,&v);
//		a[u].push_back(v);
		a[v].push_back(u);
		fa[u]=v;
	}
	scanf("%d",&q);
	for(int i=1;i<=n;i++){
		dp[i]=1e9;
	}dp[1]=1;
	int tot=0;
	for(int i=1;i<=n;i++){
		for(int j=0;j<a[i].size();j++){
//			cout<<i<<" "<<a[i][j]<<" "<<dp[a[i][j]]<<endl;
			if(!l[a[i][j]])tot++;
			if(dp[a[i][j]]==1e9){
				dp[a[i][j]]=dp[i]+1;
			}else{
				dp[a[i][j]]=min(dp[i]+1,dp[a[i][j]]);
			}
			
		}
//		i=a[i][a[i].size()-1];
		if(tot==n-1) break;
	}
//	for(int i=1;i<=n;i++){
//		cout<<dp[i]<<" "; 
//	} 
	while(q--){
		int  l,r,k;
		ans=0;
		scanf("%d%d%d",&l,&r,&k);
		for(int i=l;i<=r;i++){
			for(int j=l+k;j<=r;j++){
				ans=max(ans,dp[j]);
			}
		}
		printf("%d\n",ans);
	}
	
	return 0;
}

