#include <iostream>

const int MAXN=4e3+10;
const int MAXM=1e6+10;
using namespace std;
int father[MAXN][MAXN],depth[MAXM];
int nxt[MAXM],to[MAXM],head[MAXM],cnt=0;
int n,q;

void dfs(int u,int fa){
//	int k=2;
//	father[u][0]=u,father[u][1]=fa;
//	int f=father[fa][0];
//	while(f) father[u][k++]=f,f=father[f];
	
	for(int i=head[u];i;i=nxt[i]){
		int v=to[i];
		
		if(v==fa) continue;
		depth[v]=depth[u]+1;
		dfs(v,u);
	}
}

void add_line(int u,int v){
	nxt[++cnt]=head[u];
	to[cnt]=v;
	head[u]=cnt;
	return ;
}

int main(){
	freopen("query.in","r",stdin);
	freopen("query.out","w",stdout);
	
	scanf("%d",&n);
	for(int i=1;i<=n-1;i++){
		int x,y;
		scanf("%d%d",&x,&y);
		add_line(x,y);
		add_line(y,x);
	}
	
	depth[1]=1;
	dfs(1,0);
	scanf("%d",&q);
	while(q--){
		int k,l,r;
		scanf("%d%d%d",&l,&r,&k);
		
		int ans=1e7;
		for(int i=l;i<=r;i++){
			ans=min(ans,depth[i]);
		}
		printf("%d\n",ans);
	}
	
	fclose(stdin);
	fclose(stdout);
	
	return 0;
}
