#include<bits/stdc++.h>
#define pii pair<int,int>
#define mkp make_pair
#define fi first
#define se second
using namespace std;
namespace IO{
	const int MS=1<<20;
	char buf[MS+5];
	char *p1=buf,*p2=buf;
	char Getchar(){
		if(p1==p2){
			p1=buf;
			p2=buf+fread(buf,1,MS,stdin);
			if(p1==p2) return EOF;
		}
		return *p1++;
	}
	int Read(){
		int x=0;
		char ch=Getchar();
		while(ch<'0'||ch>'9') ch=Getchar();
		while(ch>='0'&&ch<='9') x=x*10+ch-'0',ch=Getchar();
		return x;
	}
} 
const int maxn=5e5+10;
int F[maxn][20];
int n,q,head[maxn],cnte=1,cntdfn,lg[maxn];
int mn[maxn][20],mx[maxn][20];
struct Edge{
	int to,nxt;
}e[maxn<<1];
void Add(int u,int v){
	e[cnte].to=v,e[cnte].nxt=head[u],head[u]=cnte++;
}
struct Que{
	int l,r,k,id;
}Que[maxn];
void dfs(int u,int fa,int dep){
	cntdfn++;
	mn[u][0]=mx[u][0]=cntdfn;
	F[cntdfn][0]=dep-1;
	for(int i=head[u];i;i=e[i].nxt){
		int v=e[i].to;
		if(v==fa) continue;
		dfs(v,u,dep+1);
	}
}
int lca_dep(int l,int r){
	if(l==r) return F[l][0]+1;
	l++;
	int k=lg[(r-l+1)];
	return min(F[l][k],F[r-(1<<k)+1][k]);
}
int que(int l,int r){
	int k=lg[r-l+1];
	return lca_dep(min(mn[l][k],mn[r-(1<<k)+1][k]),max(mx[l][k],mx[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-1;i++){
		int u,v;scanf("%d%d",&u,&v);
		Add(u,v),Add(v,u);
		lg[i]=((i<2)?0:lg[i>>1]+1);
	}
	lg[n]=((n<2)?0:lg[n>>1]+1);	
	dfs(1,0,1);
	for(int j=1;j<=19;j++)
		for(int i=1;i<=n-(1<<j)+1;i++)
			F[i][j]=min(F[i][j-1],F[i+(1<<(j-1))][j-1]),
			mn[i][j]=min(mn[i][j-1],mn[i+(1<<(j-1))][j-1]),
			mx[i][j]=max(mx[i][j-1],mx[i+(1<<(j-1))][j-1]);
	scanf("%d",&q);
	for(int i=1;i<=q;i++){
		scanf("%d%d%d",&Que[i].l,&Que[i].r,&Que[i].k);
		Que[i].id=i;
	}
	for(int t=1;t<=q;t++){
		int l=Que[t].l,r=Que[t].r,k=Que[t].k;
		int ans=0;
		for(int i=l;i+k-1<=r;i++)
			ans=max(ans,que(i,i+k-1));
		printf("%d\n",ans);
	}
	return 0;
}

