#include<bits/stdc++.h>
//#define int long long
using namespace std;
const int N=5e5+10;
inline int read()
{
	int x=0,f=1;
	char c=getchar();
	while(c<'0'||c>'9')
	{
		if(c=='-')f=-1;
		c=getchar();
	}
	while(c>='0'&&c<='9')x=(x<<3)+(x<<1)+(c^48),c=getchar();
	return x*f;
}
int n,q,fa[N],dep[N],son[N],siz[N],top[N];
vector<int>e[N];
void dfs1(int u)
{
	siz[u]=1;
	dep[u]=dep[fa[u]]+1;
	for(auto v:e[u])
	{
		if(v==fa[u])continue;
		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:e[u])
	{
		if(top[v])continue;
		dfs2(v,v);
	}
}
int lca(int u,int v)
{
	while(top[u]!=top[v])
	{
		if(dep[top[u]]<dep[top[v]])swap(u,v);
		u=fa[top[u]];
	}
	return dep[u]<dep[v]?u:v;
}
signed main()
{
	freopen("query.in","r",stdin);
	freopen("query.out","w",stdout);
	n=read();
	for(int i=1;i<n;i++)
	{
		int u=read(),v=read();
		e[u].push_back(v);
		e[v].push_back(u);
	}
	dfs1(1),dfs2(1,1);
	q=read();
	while(q--)
	{
		int l=read(),r=read(),k=read();
		int ans=0;
		for(int i=l;i+k-1<=n;i++)
		{
			int u=i;
			for(int v=i+1;v<i+k;v++)u=lca(u,v);
			ans=max(ans,dep[u]);
		}
		cout<<ans<<endl;
	}
}
/*
*/
