#include<bits/stdc++.h>
const int N=5e5+10;
using namespace std;
bool debug1;
int n,u,v,l,r,k,minn,ans,q,num;
int dep[N],fa[N][20];
vector<int> G[N];
bool debug2;
void dfs(int u,int father){
	dep[u]=dep[father]+1;
	fa[u][0]=father;
	for(int i=1;i<=19;i++)
		fa[u][i]=fa[fa[u][i-1]][i-1];
	for(int v:G[u]){
		if(dep[v]==0)
			dfs(v,u);
	}
}
int lca(int x,int y){
	if(dep[x]<dep[y])
		swap(x,y);
	for(int i=19;i>=0;i--)
		if(dep[fa[x][i]]>=dep[y])
			x=fa[x][i];
	if(x==y)
		return x;
	for(int i=19;i>=0;i--)
		if(fa[x][i]!=fa[y][i]){
			x=fa[x][i];
			y=fa[y][i];
		}
	return fa[x][0];
}
int main()
{
	freopen("query4.in","r",stdin);
	freopen("query.out","w",stdout);
	cout<<((&debug2-&debug1)/1024.0/1024.0)<<endl;
	scanf("%d",&n);
	for(int i=1;i<n;i++){
		scanf("%d%d",&u,&v);
		G[u].push_back(v);
		G[v].push_back(u);
	}
	dfs(1,0);
	scanf("%d",&q);
	while(q--){
		minn=num=1e9+10;
		ans=0;
		scanf("%d%d%d",&l,&r,&k);
		for(int i=l;i<=r;i++)
			if(dep[i]<minn){
				ans=i;
				minn=dep[i];
			}
		for(int i=l;i<=r;i++)
			if(ans!=i)
				num=min(num,dep[lca(ans,i)]);
		printf("%d\n",num);
	}
	return 0;
}

