#include<cstdio>
#include<queue>
char Begin;
int min(int x,int y){return x<y?x:y;}
int max(int x,int y){return x>y?x:y;}
int read(){
	int num=0;
	char ch;ch=getchar();
	while(ch<48||ch>57)ch=getchar();
	while(ch>47&&ch<58){
		num=(num<<1)+(num<<3)+(ch^48);
		ch=getchar();
	}return num;
}
const int N=5e5+5;
int n,m;
int em,e[N<<1],nx[N<<1],ls[N];
void insert(int x,int y){
	e[++em]=y;
	nx[em]=ls[x];
	ls[x]=em;
}
int dep[N],fir[N];
int lo[N<<1],w[25];
int f[N][25],g[N][25];
int mn[N<<1][25],whe[N<<1][25],cnt;
int mx;
void dg(int x,int father){
	dep[x]=dep[father]+1;
	mn[++cnt][0]=dep[x];
	whe[cnt][0]=x;
	mx=max(mx,dep[x]);
	fir[x]=cnt;
	for(int i=ls[x];i;i=nx[i]){
		if(e[i]==father)continue;
		dg(e[i],x);
		mn[++cnt][0]=dep[x];
		whe[cnt][0]=x;
	}
}
int Q(int l,int r){
	if(l>r)l^=r,r^=l,l^=r;
	int x=lo[r-l+1];
	return min(mn[l][x],mn[r-w[x]+1][x]);
}
int ask(int l,int r){
	if(l>r)l^=r,r^=l,l^=r;
	int x=lo[r-l+1];
	if(dep[whe[l][x]]<dep[whe[r-w[x]+1][x]])return whe[l][x];
	else return whe[r-w[x]+1][x];
}
int Ask(int l,int r){
	if(l>r)l^=r,r^=l,l^=r;
	int x=lo[r-l+1];
	return Q(min(f[l][x],f[r-w[x]+1][x]),max(g[l][x],g[r-w[x]+1][x]));
}
int Ask1(int l,int r){
	if(l>r)l^=r,r^=l,l^=r;
	int x=lo[r-l+1];
	return ask(min(f[l][x],f[r-w[x]+1][x]),max(g[l][x],g[r-w[x]+1][x]));
}
struct node{
	int l,r;
	int d;
};
bool operator<(node x,node y){return x.d>y.d;}
std::priority_queue<node>d;
int ans;
char End;
int main(){
//	printf("%d\n",(&End-&Begin)/1024);
	freopen("query.in","r",stdin);
	freopen("query.out","w",stdout);
	n=read();
	for(int i=1,p,q;i<n;i++){
		p=read(),q=read();
		insert(p,q);
		insert(q,p);
	}
	dg(1,0);
	for(int i=0;i<20;i++)w[i]=(1<<i);
	lo[0]=-1;
	for(int i=1;i<=cnt;i++)lo[i]=lo[i>>1]+1;
	for(int i=1;i<=n;i++)f[i][0]=g[i][0]=fir[i];
	for(int i=1;i<20;i++)
		for(int j=1;j+w[i]-1<=n;j++)
			f[j][i]=min(f[j][i-1],f[j+w[i-1]][i-1]),
			g[j][i]=max(g[j][i-1],g[j+w[i-1]][i-1]);
	for(int i=1;i<20;i++)
		for(int j=1;j+w[i]-1<=cnt;j++){
			mn[j][i]=min(mn[j][i-1],mn[j+w[i-1]][i-1]);
			if(dep[whe[j][i-1]]<dep[whe[j+w[i-1]][i-1]])whe[j][i]=whe[j][i-1];
			else whe[j][i]=whe[j+w[i-1]][i-1];
		}
	if(mx==n){
		m=read();
		while(m--){
			int l=read(),r=read(),K=read();
			ans=Ask(l,r);
			d.push(node{l,r,Ask(l,r)});
			while(!d.empty()){
				node now=d.top();d.pop();
				ans=max(ans,now.d);
				int u=Ask1(now.l,now.r);
				if(u-now.l>=K)d.push(node{now.l,u-1,Ask(now.l,u-1)});
				if(now.r-u>=K)d.push(node{u+1,now.r,Ask(u+1,now.r)});
			}
			printf("%d\n",ans);
		}
		return 0;
	}
	m=read();
	while(m--){
		int l=read(),r=read(),K=read();
		ans=Ask(l,r);
		for(int L=l,R=l+K-1;R<=r;L++,R++)
			ans=max(ans,Ask(L,R));
		printf("%d\n",ans);
	}
	return 0;
}
