#include<bits/stdc++.h>
#define il inline
using namespace std;
const int M=500005;
int n,u,v,tot,l,r,k,q;
int h[M],to[M<<1],nxt[M<<1];
void add_edge(int u,int v){
	to[++tot]=v;
	nxt[tot]=h[u];
	h[u]=tot;
}
int siz[M],son[M],fa[M],tp[M],dep[M],mdep;
void dfs(int x,int f,int d){
	siz[x]=1,fa[x]=f,dep[x]=d;
	mdep=max(mdep,d);
	for(int i=h[x];i;i=nxt[i]){
		if(to[i]==f) continue;
		dfs(to[i],x,d+1);
		siz[x]+=siz[to[i]];
		if(siz[to[i]]>siz[son[x]])
			son[x]=to[i];
	}
}
void dfs2(int x,int t){
	tp[x]=t;
	if(son[x]) dfs2(son[x],t);
	for(int i=h[x];i;i=nxt[i]){
		if(to[i]==fa[x]||to[i]==son[x]) continue;
		dfs2(to[i],to[i]);
	}
}
il int getlca(int x,int y){
	if(x==0||y==0) return x+y;
	while(tp[x]!=tp[y]){
		if(dep[tp[x]]<dep[tp[y]])
			swap(x,y);
		x=fa[tp[x]];
	}
	return dep[x]<dep[y]?x:y;
}
const int M2=5005;
int lcadep[M2][M2],nlca,ans,LCA;
int tr[M<<3];
void build(int x,int l,int r){
	if(l==r){
		tr[x]=l;
		return;
	}
	int mid=l+r>>1;
	build(x<<1,l,mid);
	build(x<<1|1,mid+1,r);
	tr[x]=getlca(tr[x<<1],tr[x<<1|1]);
}
int query(int x,int l,int r,int ql,int qr){
	if(ql<=l&&r<=qr)
		return tr[x];
	int res=0,mid=l+r>>1;
	if(ql<=mid) res=getlca(res,query(x<<1,l,mid,ql,qr));
	if(qr>mid) res=getlca(res,query(x<<1|1,mid+1,r,ql,qr));
	return res;
}
int main(){
	freopen("query.in","r",stdin);
	freopen("query.out","w",stdout);
	scanf("%d",&n);
	for(int i=1;i<n;i++){
		scanf("%d%d",&u,&v);
		add_edge(u,v);
		add_edge(v,u);
	}
	scanf("%d",&q);
	if(n<=5000){
		dfs(1,0,1);
		dfs2(1,1);
		for(int i=1;i<=n;i++){
			nlca=i,lcadep[i][i]=dep[i];
			for(int j=i+1;j<=n;j++){
				nlca=getlca(nlca,j);
				lcadep[i][j]=dep[nlca];
			}
		}
		while(q--){
			scanf("%d%d%d",&l,&r,&k);
			ans=0;for(int i=l,j=l+k-1;j<=r;i++,j++)
				ans=max(ans,lcadep[i][j]);
			printf("%d\n",ans);
		}
	}
	else{
		dfs(1,0,1);
		dfs2(1,1);
		build(1,1,n);
		while(q--){
			scanf("%d%d%d",&l,&r,&k);
			ans=dep[query(1,1,n,l,r)];
			printf("%d\n",ans);
		}
	}
	fclose(stdin);
	fclose(stdout);
	return 0;
} 
