#include<bits/stdc++.h>
#define pb push_back
#define il inline
using namespace std;
const int N=5e5+5;
int n,q,deg[N],flag;
vector<int> g[N];
int fa[N],dep[N],siz[N],hs[N];
void dfs1(int u,int fath)
{
	fa[u]=fath,dep[u]=dep[fath]+1;
	siz[u]=1,hs[u]=-1;
	for(auto v:g[u])
	{
		if(v==fath) continue;
		dfs1(v,u),siz[u]+=siz[v];
		if(hs[u]==-1||siz[v]>siz[hs[u]]) hs[u]=v;
	}
}
int top[N];
void dfs2(int u,int t)
{
	top[u]=t;
	if(~hs[u]) dfs2(hs[u],t);
	for(auto v:g[u])
		if(v^hs[u]&&fa[u]^v) dfs2(v,v);
}
il 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]];
	}
	if(dep[u]<dep[v]) swap(u,v);
	return v;
}
namespace DEP
{
	int st[N][23],LOG[N];
	il void st_init()
	{
		LOG[0]=-1;
		for(int i=1;i<=n;i++)
		{
			LOG[i]=LOG[i>>1]+1;
			st[i][0]=dep[i];
		}
		int p=LOG[n];
		for(int k=1;k<=p;k++)
			for(int s=1;s+(1<<k)<=n+1;s++)
				st[s][k]=max(st[s][k-1],st[s+(1<<(k-1))][k-1]);
	}
	il int st_query(int L,int R)
	{
		int k=LOG[R-L+1];
		return max(st[L][k],st[R-(1<<k)+1][k]);
	}	
}
namespace LCAA
{
	int st[N][23],LOG[N];
	il void st_init()
	{
		LOG[0]=-1;
		for(int i=1;i<=n;i++)
		{
			LOG[i]=LOG[i>>1]+1;
			st[i][0]=i;
		}
		int p=LOG[n];
		for(int k=1;k<=p;k++)
			for(int s=1;s+(1<<k)<=n+1;s++)
				st[s][k]=LCA(st[s][k-1],st[s+(1<<(k-1))][k-1]);
	}
	il int st_query(int L,int R)
	{
		int k=LOG[R-L+1];
		return LCA(st[L][k],st[R-(1<<k)+1][k]);
	}
}
int main()
{
	freopen("query.in","r",stdin);
	freopen("query.out","w",stdout);
	scanf("%d",&n);
	for(int i=1;i<n;i++)
	{
		int u,v;
		scanf("%d%d",&u,&v);
		g[u].pb(v),g[v].pb(u);
		deg[u]++,deg[v]++;
	}
	dfs1(1,0),dfs2(1,1);
	DEP::st_init();
	LCAA::st_init();
	scanf("%d",&q);
	while(q--)
	{
		int l,r,k;
		scanf("%d%d%d",&l,&r,&k);
		if(k==1)
		{
			printf("%d\n",DEP::st_query(l,r));
			continue;
		}
		int ans=0;
		for(int i=l,j=l+k-1;j<=r;i++,j++)
			ans=max(ans,dep[LCAA::st_query(i,j)]);
		printf("%d\n",ans);
	}
	return 0;
}
