#include<bits/stdc++.h>
using namespace std;
const int N=5e5+1e4;
const int inf=1e9+7;
struct rec{
	int e,nex;	
}z[2*N];
int en,fi[N];
void add(int s,int e){
	z[++en].e=e;
	z[en].nex=fi[s];
	fi[s]=en;
}
int deep[N],top[N],siz[N],son[N],f[N];
void dfs1(int u,int fa){
	f[u]=fa;
	deep[u]=deep[fa]+1;
	siz[u]=1;
	son[u]=-1;
	int p=-1;
	for (int i=fi[u];i!=0;i=z[i].nex){
		if (z[i].e==fa) continue;
		dfs1(z[i].e,u);
		siz[u]+=siz[z[i].e];
		if (p==-1||siz[p]<siz[z[i].e]) p=z[i].e; 
	}
	son[u]=p;
}
void dfs2(int u,int topp){
	top[u]=topp;
	if (son[u]==-1) return ;
	dfs2(son[u],topp);
	for (int i=fi[u];i!=0;i=z[i].nex){
		if (z[i].e==f[u]||z[i].e==son[u]) continue;
		dfs2(z[i].e,z[i].e);
	}
}
int q_lca(int x,int y){
	while (top[x]!=top[y]){
		if (deep[top[x]]<deep[top[y]]){
			swap(x,y);
		}
		x=f[top[x]];
	}
	return deep[x]<deep[y]?x:y;
} 
int n,q;
int in[N];
void init(){
	scanf("%d",&n);
	for (int i=1;i<n;++i){
		int s,e;
		scanf("%d%d",&s,&e);
		add(s,e);
		add(e,s);
		in[s]++;
		in[e]++;
	}
	scanf("%d",&q);
}
int ans=inf;
void work1(){
	dfs1(1,0);
	dfs2(1,1);
	for (int i=1;i<=q;++i){
		int l,r,k;
		scanf("%d%d%d",&l,&r,&k);
		ans=inf;
		int lca;
		for (int j=l;j+k-1<=r;++j){
			lca=j;
			for (int g=j+1;g<=j+k-1;++g){
				lca=q_lca(lca,g);
			}
			if (ans==inf||deep[ans]<deep[lca]) ans=lca;
		}
		printf("%d\n",deep[ans]);
	} 
}
int main(){
	freopen("query.in","r",stdin);
	freopen("query.out","w",stdout);
	init();
	work1();
	return 0;
}
