#include<bits/stdc++.h>
using namespace std;
const int N=5e5+10;
int in()
{
	int w=0,f=1;
	char c=getchar();
	while(!isdigit(c))
	{
		if(c=='-') f=-1;
		c=getchar();
	}
	while(isdigit(c))
	{
		w=w*10+c-'0';
		c=getchar();
	}
	return w*f;
}
void out(int w)
{
	if(w<0) 
	{
		putchar('-');
		out(-w);
		return;
	}
	if(w>=10) out(w/10);
	putchar(w%10+'0');
}
vector<int>g[N];
int n,u,v,d[N],vis[N],q,l,r,k,tr[N*4];
void build(int x,int l,int r)
{
	if(l==r) 
	{
		tr[x]=d[l];
		return;
	}
	int mid=l+r>>1;
	build(x*2,l,mid);
	build(x*2+1,mid+1,r);
	tr[x]=max(tr[x*2],tr[x*2+1]);
}
int get(int x,int l,int r,int kl,int kr)
{
	if(kl<=l&&r<=kr) return tr[x];
	int mid=l+r>>1,ans=0;
	if(kl<=mid) ans=get(x*2,l,mid,kl,kr);
	if(kr>mid) ans=max(ans,get(x*2+1,mid+1,r,kl,kr));
	return ans;
}
int main()
{
	freopen("query.in","r",stdin);
	freopen("query.out","w",stdout);
	cin>>n;
	for(int i=1;i<n;i++)
	{
		u=in();v=in();
		g[u].push_back(v);
		g[v].push_back(u);
	}
	vis[1]=1;
	d[1]=1;
	int m=n-1,ls=1;
	while(m--)
		for(int i=0;i<g[ls].size();i++)
		{
			int v=g[ls][i];
			if(!vis[v])
			{
				vis[v]=1;
				d[v]=d[ls]+1;
				ls=v;
			}
		}
	cin>>q;
	while(q--)
	{
		int minn=1000000010;
		l=in();r=in();k=in();
		for(int i=l;i<=r;i++) minn=min(minn,d[i]);
		out(minn);
		putchar('\n');
	}
	return 0;
 } 
