#include<algorithm>
#include<iostream>
#include<cstdio>
#include<vector>
#include<cstring>
#include<map>
using namespace std;
const int N=5e5+10;
vector<int> e[N];
int read() {
	int s=0; char ch=getchar();
	while(ch<'0'||ch>'9') ch=getchar();
	while(ch>='0'&&ch<='9') s=10*s+ch-'0',ch=getchar();
	return s;
}
int n,q,dfn[N],num,dep[N],ed[N],Md[N][21],Fx[N],lc[N][21];
int get(int u,int v) {
	if(dep[u]<dep[v]) return u;
	return v;
}
int lca(int u,int v) {
	if(dep[u]>dep[v]) swap(u,v);
	if(dfn[v]>=dfn[u]&&dfn[v]<=ed[u]) return u;
	u=dfn[u],v=dfn[v];
	if(u>v) swap(u,v);
//	printf("dfn = %d\n",Md[u][1]);
	int p=__lg(v-u+1);
	return Fx[get(Md[u][p],Md[v-(1<<p)+1][p])];
}
int qqlca(int l,int r) {
	int p=__lg(r-l+1);
	return lca(lc[l][p],lc[r-(1<<p)+1][p]);
}
void dfs(int u,int fa) {
	Fx[u]=fa;
	dep[u]=dep[fa]+1; dfn[u]=++num;
	Md[dfn[u]][0]=u;
	for(int v:e[u]) 
		if(v!=fa) dfs(v,u);
	ed[u]=num;
}
void solve1() {
	for(; q; q--) {
		int l=read(),r=read(),k=read(),ans=0;
		for(int i=l,j=l+k-1; j<=r; i++,j++)
			ans=max(ans,dep[qqlca(i,j)]);
		printf("%d\n",ans);
	} 
}
void solve2() {
	for(; q; q--) {
		int l=read(),r=read(),k=read();
		if(k==r-l+1) printf("%d\n",qqlca(l,r));
	} 
} 
int main() {
	freopen("query.in","r",stdin);
	freopen("query.out","w",stdout);
	n=read();
	for(int i=1; i<n; i++) {
		int u=read(),v=read();
		e[u].push_back(v); e[v].push_back(u);
	}
	dfs(1,1);
	for(int j=1; j<=20; j++) for(int i=1; i+(1<<j)-1<=n; i++)
		Md[i][j]=get(Md[i+(1<<(j-1))][j-1],Md[i][j-1]);
	for(int i=1; i<=n; i++) lc[i][0]=i;
	for(int j=1; j<=20; j++) for(int i=1; i+(1<<j)-1<=n; i++)
		lc[i][j]=lca(lc[i+(1<<(j-1))][j-1],lc[i][j-1]);
	q=read();
	if(n<=5000&&q<=5000) solve1();
	else solve2();
	return 0;
}
