#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
const int N=5e5+5;
int n,q;
int head[N],idx;
struct Edge{
	int v,next;
}adj[N<<1];
void ins(int x,int y){
	adj[++idx].v=y;
	adj[idx].next=head[x];
	head[x]=idx;
}
int dep[N],f[N][21];
void dfs(int u,int fa){
	dep[u]=dep[fa]+1;
	for(int i=head[u];i;i=adj[i].next){
		int v=adj[i].v;
		if(v==fa)continue;
		f[v][0]=u;
		for(int j=1;(1<<j)<=dep[u];j++){
			f[v][j]=f[f[v][j-1]][j-1];
		}
		dfs(v,u);
	}
}
int lca(int x,int y){
	if(dep[x]<dep[y])swap(x,y);
	for(int i=20;i>=0;i--){
		if(dep[f[x][i]]>=dep[y])
			x=f[x][i];
	}
	if(x==y)return x;
	for(int i=20;i>=0;i--){
		if(f[x][i]!=f[y][i])
			x=f[x][i],y=f[y][i];
	}
	return f[x][0];
}
struct Sgt{
	#define ls (p<<1)
	#define rs (p<<1|1)
	#define mid ((l+r)>>1)
	int av[N<<2];
	void pushup(int p){
		av[p]=lca(av[ls],av[rs]);
	}
	void build(int p,int l,int r){
		if(l==r){av[p]=l;return ;}
		build(ls,l,mid);
		build(rs,mid+1,r);
		pushup(p);
	}
	int query(int p,int l,int r,int L,int R){
		if(L<=l&&r<=R)return av[p];
		int ra=0,rb=0;
		if(L<=mid)ra=query(ls,l,mid,L,R);
		if(R>mid)rb=query(rs,mid+1,r,L,R);
		if(ra&&rb)return lca(ra,rb);
		return ra|rb;
	}
}T;
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);
		ins(u,v);ins(v,u);
	}
	dfs(1,0);
	T.build(1,1,n);
	scanf("%d",&q);
	while(q--){
		int l,r,k;
		scanf("%d%d%d",&l,&r,&k);
		int ans=0;
		for(int i=l;i+k-1<=r;i++){
			ans=max(ans,dep[T.query(1,1,n,i,i+k-1)]);
		}
		printf("%d\n",ans);
	}
	return 0;
}
