#include<bits/stdc++.h>
#define fo(i,a,b) for(int i=(a);i<=(b);++i) 
#define fd(i,a,b) for(int i=(a);i>=(b);--i) 
#define fu(i,a,b) for(int i=(a);i<(b);++i)
#define ll long long 
using namespace std;
const int N=5e5+5;
char St;
int n,q,l,r,k,u,v,col[N],dep[N],fa[N],ans;
int eul[N<<1],ST[21][N<<1],cnt,ks[N<<1],js[N<<1],lg[N<<1];
int anss[20][N];
int tot,nt[N<<1],to[N<<1],fi[N];
inline void link(int x,int y){++tot;nt[tot]=fi[x];to[tot]=y;fi[x]=tot;}
void dfs(int x)
{
	++cnt;eul[cnt]=x;ks[x]=cnt;
	for(int i=fi[x];i;i=nt[i])
	{
		int y=to[i];
		if(y!=fa[x])fa[y]=x,dep[y]=dep[x]+1,dfs(y),++cnt,eul[cnt]=x;
	}
	js[x]=cnt;
}
inline int query(int x,int y)
{
	int K=lg[y-x+1],v1=ST[K][x],v2=ST[K][y-(1<<K)+1];
	if(dep[v1]<dep[v2])return v1;
	else return v2;
}
inline int lca(int x,int y){return query(min(ks[x],ks[y]),max(js[x],js[y]));}
inline int qry(int x,int y)
{
	int K=lg[y-x+1];
	return lca(anss[K][x],anss[K][y-(1<<K)+1]);
}
void init()
{
	dep[1]=1;dfs(1);lg[1]=0;
	fo(i,2,cnt)lg[i]=lg[i>>1]+1;
	fo(i,1,cnt)ST[0][i]=eul[i];
	fo(j,1,lg[cnt])fo(i,1,cnt)if(i+(1<<j-1)<=cnt)
	{
		int v1=ST[j-1][i],v2=ST[j-1][i+(1<<j-1)];
		if(dep[v1]<dep[v2])ST[j][i]=v1;
		else ST[j][i]=v2;
	}
	else ST[j][i]=ST[j-1][i];
	fo(i,1,n)anss[0][i]=i;
	fo(j,1,lg[n])fo(i,1,n)if(i+(1<<j-1)<=n)anss[j][i]=lca(anss[j-1][i],anss[j-1][i+(1<<j-1)]);
	else anss[j][i]=anss[j-1][i];
}
char Ed;
int main()
{
	freopen("query.in","r",stdin);
	freopen("query.out","w",stdout);
	scanf("%d",&n);
	fu(i,1,n)scanf("%d%d",&u,&v),link(u,v),link(v,u);
	init();scanf("%d",&q);
	while(q--)
	{
		scanf("%d%d%d",&l,&r,&k);
		int ed=r-k+1;ans=0;
		fo(i,l,ed)ans=max(ans,dep[qry(i,i+k-1)]);
		printf("%d\n",ans);
	}
	return 0;
}
