#include<iostream>
#include<cstdio>
#include<cstdlib>
#define N 500005
using namespace std;
int n,q;
struct EDGE{
	int to,next;
}edge[N];
int head[N];
int vis[N];
int dfn[N];
int cnt;
void addedge(int u,int v){
	cnt++;
	edge[cnt].next=head[u];
	edge[cnt].to=v;
	head[u]=cnt;
}
void dfs(int p,int sd){
	dfn[p]=sd;
	for(int i=head[p];i;i=edge[i].next){
		int v=edge[i].to;
		if(!vis[v]){
			vis[v]=1;
			dfs(v,sd+1);
		}
	}
}
int main(){
	freopen("query.in","r",stdin);
	freopen("query.out","w",stdout);
	cin>>n;
	for(int i=1;i<n;i++){
		int u,v;
		scanf("%d%d",&u,&v);
		addedge(u,v);
	}
	dfs(1,0);
	vis[1]=1;
	cin>>q;
	for(int i=1;i<=q;i++){
		int l,r,k;
		cin>>l>>r>>k;
		int ans=0x3f3f3f3f;
		for(int j=l;j<=r;j++){
			ans=min(ans,dfn[j]);
		}
		printf("%d\n",ans+1);
	}
	return 0;
}
