#include<bits/stdc++.h>
using namespace std;
int read()
{
	int x=0,w=1;
	char c=0;
	while(c<'0'||c>'9')
	{
		if(c=='-')w=-1;
		c=getchar();
	}
	while(c>='0'&&c<='9')
	{
		x=(x<<1)+(x<<3)+c-'0';
		c=getchar();
	}
	return x*w;
}
const int maxn=5e5+9;
vector<int>G[maxn]; 
int dep[maxn],siz[maxn],son[maxn],top[maxn],fa[maxn];
void dfs1(int u)
{
	siz[u]=1;
	for(auto v:G[u])
	{
		if(siz[v])continue;
		dep[v]=dep[u]+1;
		fa[v]=u;
		dfs1(v);
		siz[u]+=siz[v];
		if(siz[v]>siz[son[u]])son[u]=v;
	}
}
void dfs2(int u,int t)
{
	top[u]=t;
	if(!son[u])return;
	dfs2(son[u],t);
	for(auto v:G[u])
	{
		if(v==fa[u]||v==son[u])continue;
		dfs2(v,v);
	}
}	
int LCA(int x,int y)
{
	while(top[x]!=top[y])
	{
		if(dep[top[x]]>dep[top[y]])
		{
			x=fa[top[x]];
		}
		else
		{
			y=fa[top[y]];
		}
	}
	if(dep[x]<dep[y])return x;
	else return y;
}
int lca[5009][5009];
int main()
{
	freopen("query.in","r",stdin);
	freopen("query.out","w",stdout);
	int n;
	n=read();
	for(int i=1;i<n;i++)
	{
		int u,v;
		u=read();v=read();
		G[u].push_back(v);
		G[v].push_back(u);
	}
	dep[1]=1;
	dfs1(1);dfs2(1,1);
	for(int i=1;i<=n;i++)
	{
		for(int j=1;j<=n;j++)
		{
	//		printf("%d %d %d\n",i,j,LCA(i,j));
			lca[i][j]=LCA(i,j);
		}
	}
	int q;
	q=read();
	while(q--)
	{
		int l,r,k;
		l=read();r=read();k=read();
		int ans=0;
		for(int len=k;len<=r-l+1;len++)
		{
			if(len==1)
			{
				for(int j=l;j<=r;j++)ans=max(ans,dep[j]);
				continue;
			}
			for(int i=l,j=l+len-1;j<=r;i++,j++)
			{
				
				int cnt=lca[i][i+1];
				for(int k=i+2;k<=j;k++)
				{
					cnt=lca[cnt][k];
				}
				ans=max(ans,dep[cnt]);
			}
		}
		printf("%d\n",ans);
	}
	return 0;
}

