#include <bits/stdc++.h>
#define For(e,e1,e2) for(int e=(e1);e<=(e2);e++)
#define For_(e,e1,e2) for(int e=(e1);e<(e2);e++)
#define Rof(e,e1,e2) for(int e=(e2);e>=(e1);e--)
#define Rof_(e,e1,e2) for(int e=(e2);e>(e1);e--)
#define exc(e) if(e) continue
#define stop(e) if(e) break
#define ret(e) if(e) return 
#define LL long long
#define ULL unsigned long long
#define DB double
#define cint const int
#define cLL const long long
#define vct vector
#define pb push_back
#define ft first
#define sc second
using namespace std;
void main_init()
{
	
}
void get_min(int &w1,int w2)
{
	if(w2<w1) w1=w2;
}
void get_max(int &w1,int w2)
{
	if(w2>w1) w1=w2;
}
cint N=500100;
int n,tot;
vct <int> v[N];
int dep[N],d[N<<1],in[N],out[N];
void dfs(int p,int fa)
{
	d[++tot]=p; in[p]=tot;
	dep[p]=dep[fa]+1;
	for(auto i:v[p])
	{
		exc(i==fa);
		dfs(i,p);
		d[++tot]=p;
	}
	out[p]=tot;
}
cint K=20;
int st[K+1][N<<1],st2[K+1][N];
int st_qry(int l,int r)
{
	int x=__lg(r-l+1);
	int p1=st[x][l],p2=st[x][r-(1<<x)+1];
	return (dep[p1]<dep[p2]?p1:p2);
}
int lca(int x,int y)
{
	if(in[x]>in[y]) swap(x,y);
	return st_qry(in[x],in[y]);
}
int lca2(int l,int r)
{
	int x=__lg(r-l+1);
	return lca(st2[x][l],st2[x][r-(1<<x)+1]);
}
void main_solve()
{
	scanf("%d",&n);
	For_(i,1,n)
	{
		int x,y; scanf("%d%d",&x,&y);
		v[x].pb(y),v[y].pb(x);
	}
	tot=0;
	dfs(1,0);
	For(i,1,tot) st[0][i]=d[i];
	For(j,1,K) For(i,1,tot)
	{
		st[j][i]=st[j-1][i];
		int i2=i+(1<<j-1);
		if(i2<=tot&&dep[st[j-1][i2]]<dep[st[j][i]])
			st[j][i]=st[j-1][i2];
	}
	For(i,1,n) st2[0][i]=i;
	For(j,1,K) For(i,1,n)
	{
		st2[j][i]=st2[j-1][i];
		int i2=i+(1<<j-1);
		if(i2<=n) st2[j][i]=lca(st2[j][i],st2[j-1][i2]);
	}
//	while(true)
//	{
//		int x,y; scanf("%d%d",&x,&y);
//		printf("%d\n",lca2(x,y));
//	}
	int Q; scanf("%d",&Q);
	while(Q--)
	{
		int l2,r2,len; scanf("%d%d%d",&l2,&r2,&len);
		int ans=1;
		for(int l=l2,r=l2+len-1;r<=r2;l++,r++)
			get_max(ans,dep[lca2(l,r)]);
		printf("%d\n",ans);
	}
}
int main()
{
	freopen("query.in","r",stdin);
	freopen("query.out","w",stdout);
	main_init();
//	int _; scanf("%d",&_); while(_--) 
		main_solve();
	return 0;
}
/*
6
5 6
6 1
6 2
2 3
2 4
3
2 5 2
1 4 1
1 6 3

*/
