#include <iostream>
#include <cstring>
#include <vector>

using namespace std;

const int N=1e6+5;

int n,q,dep[N],dfn[N],eln[N],did[N],low[N],lg[N];
int st1[N][20],st2[N][20],st3[N][20];// dfnmin dfnmax elnmin
vector<int> e[N];

void dfs(int u,int fa){
	dep[u]=dep[fa]+1;
	dfn[++dfn[0]]=u,did[u]=dfn[0];
	eln[++eln[0]]=dep[u],low[u]=eln[0];
	for (auto j:e[u])
		if (j^fa) dfs(j,u),eln[++eln[0]]=dep[u];
}

int Min1(int u,int v){
	return did[u]<did[v]?u:v;
}

int Max2(int u,int v){
	return did[u]>did[v]?u:v;
}

int dlca(int u,int v){
	u=low[u],v=low[v];
	if (u>v) swap(u,v);
	int j=lg[v-u+1];
	return min(st3[u][j],st3[v-(1<<j)+1][j]);
}

int Mind(int l,int r){
	int j=lg[r-l+1];
	return Min1(st1[l][j],st1[r-(1<<j)+1][j]);
}

int Maxd(int l,int r){
	int j=lg[r-l+1];
	return Max2(st2[l][j],st2[r-(1<<j)+1][j]);
}

int main(){
	freopen("query.in","r",stdin),freopen("query.out","w",stdout);
	ios::sync_with_stdio(0),cin.tie(0);
	cin>>n;
	for (int i=1,u,v;i<n;i++)
		cin>>u>>v,e[u].push_back(v),e[v].push_back(u);
	dfs(1,0);
	for (int i=1;i<=n;i++) st1[i][0]=st2[i][0]=i;
	for (int j=1;1<<j<=n;j++)
		for (int i=1;i+(1<<j)-1<=n;i++)
			st1[i][j]=Min1(st1[i][j-1],st1[i+(1<<j-1)][j-1]),
			st2[i][j]=Max2(st2[i][j-1],st2[i+(1<<j-1)][j-1]);
	lg[0]=-1;
	for (int i=1;i<=eln[0];i++)
		lg[i]=lg[i>>1]+1,st3[i][0]=eln[i];
	for (int j=1;1<<j<=eln[0];j++)
		for (int i=1;i+(1<<j)-1<=eln[0];i++)
			st3[i][j]=min(st3[i][j-1],st3[i+(1<<j-1)][j-1]);
	cin>>q;
	while (q--){
		int l,r,k,ans=-1;
		cin>>l>>r>>k;
		for (int a=l,b=a+k-1;b<=r;a++,b++)
			ans=max(ans,dlca(Mind(a,b),Maxd(a,b)));
		cout<<ans<<"\n";
	}
	cout<<flush,fclose(stdin),fclose(stdout);	
	return 0;
} 
