#include<bits/stdc++.h>
using namespace std;

const int N=500005;

int n,q,f[N][25];
int lca[N][25],dep[N];
bool lian=1;
vector<int> g[N];

int read(){
	int ff=1,kk=0;
	char ch=getchar();
	while(ch<'0'||ch>'9'){
		if(ch=='-')ff=-1;
		ch=getchar();
	}
	while(ch>='0'&&ch<='9'){
		kk=kk*10+ch-'0';
		ch=getchar();
	}
	return ff*kk;
}

void dfs(int x){
	for(int i(1);i<=18;++i)f[x][i]=f[f[x][i-1]][i-1];
	if(g[x].size()>2)lian=0;
	for(int i(0);i<g[x].size();++i){
		int v=g[x][i];
		if(v==1||f[v][0])continue;
		dep[v]=dep[x]+1;
		f[v][0]=x;
		dfs(v);
	}
	return;
}

int getlca(int x,int y){
//	printf("lca %d %d=",x,y);
	if(dep[x]<dep[y])swap(x,y);
	if(dep[x]>dep[y])
		for(int i(18);i>=0;--i)
			if(dep[f[x][i]]>=dep[y])x=f[x][i];
//	if(x==y)printf("qwq%d\n",x);
	if(x==y)return x;
	for(int i(18);i>=0;--i)
		if(f[x][i]!=f[y][i])
			x=f[x][i],y=f[y][i];
//	printf("%d\n",f[x][0]);
	return f[x][0];
}

int find(int x,int y){
	int k=log2(y-x+1);
	if((1<<k)==y-x+1)return dep[lca[x][k]];
	return dep[getlca(lca[x][k],lca[y-(1<<k)+1][k])];
}

int main(){
//	system("fc query2.ans query2.out");
	freopen("query.in","r",stdin);
	freopen("query.out","w",stdout);
	//cout<<log2(N)<<'\n';//18.93....
	n=read();
	for(int i(1);i<n;++i){
		int u=read(),v=read();
		g[u].push_back(v);
		g[v].push_back(u);
	}
	dep[1]=1;
	dfs(1);
	//for(int i(1);i<=n;++i)cout<<dep[i]<<" ";puts("");
	//puts("qwq");
	if(lian){
		for(int i(1);i<=n;++i)lca[i][0]=i;
		for(int k(1);k<=18;++k){
			for(int i(1);i<=n-(1<<k)+1;++i){
				if(dep[lca[i][k-1]]<dep[lca[i+(1<<(k-1))][k-1]])
					lca[i][k]=lca[i][k-1];
				else lca[i][k]=lca[i+(1<<(k-1))][k-1];
			}
		}
	}
	else{
		for(int i(1);i<=n;++i)lca[i][0]=i;
		for(int k(1);k<=18;++k)
			for(int i(1);i<=n-(1<<k)+1;++i)
				lca[i][k]=getlca(lca[i][k-1],lca[i+(1<<(k-1))][k-1]);
	}
/*	for(int i(1);i<=n;++i)
		for(int j(i);j<=n;++j)printf("%d %d : %d\n",i,j,find(i,j));*/
	q=read();
	while(q--){
		int l=read(),r=read(),k=read();
		int ans=0;
		for(int i(l);i<=r-k+1;++i){
			int res=find(i,i+k-1);
			if(res>ans)ans=res;
		}
		printf("%d\n",ans);
	}
	return 0;
} 
