#include<bits/stdc++.h>
using namespace std;
const int maxn=5e5+5;
int n,sum,q,dep[25][maxn];
vector<int> vec[maxn];
bool ok1=1;
void dfs(int u,int fa)
{
	for(int v:vec[u])
	{
		if(v!=fa)
		{
			dep[0][v]=dep[0][u]+1;
			dfs(v,u);
		}
	}
	return;
}
int main()
{
	freopen("query.in","r",stdin);
	freopen("query.out","w",stdout);
	cin>>n;
	for(int i=1;i<n;i++)
	{
		int u,v;
		cin>>u>>v;
		vec[u].push_back(v);
		vec[v].push_back(u);
	}
	for(int i=1;i<=n;i++)
		if(vec[i].size()>2)
			ok1=0;
	if(ok1)
	{
		dfs(1,0);
		cin>>q;
		for(int i=1;i<=19;i++)
			for(int j=1;j+(1<<i)-1<=n;j++)
				 dep[i][j]=min(dep[i-1][j],dep[i-1][j+(1<<(i-1))]);
		while(q--)
		{
			int l,r,k;
			cin>>l>>r>>k;
			int lg=log2(r-l+1);
			cout<<min(dep[lg][l],dep[lg][r-(1<<lg)+1])<<"\n";
		}
	}
	else
	{
		cin>>q;
		while(q--)
		{
			random_device rd;
			mt19937 op(rd());
			cout<<(op())%n;
		}
	}
	return 0;
}
