#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
using namespace std;

int n,q,K;
int head[500005],to[1000005],nxt[1000005],ecnt=0;
int f[500005][23];
int g[500005][23];
int dep[500005];
int lg2[500005];

void add(int u,int v){
	to[++ecnt]=v;
	nxt[ecnt]=head[u];
	head[u]=ecnt;
}

void dfs(int u,int fa){
	f[u][0]=fa;
	dep[u]=dep[fa]+1;
	for(int i=head[u];i;i=nxt[i]){
		int v=to[i];
		if(v==fa){
			continue;
		}
		dfs(v,u);
	}
}

int getlca(int u,int v){
	if(dep[u]<dep[v])swap(u,v);
	for(int i=K;i>=0;i--){
	//	cout<<f[u][i]<<"  "<<v<<endl;
		if(dep[f[u][i]]>=dep[v]){
			u=f[u][i];
		}
	}
//	cout<<u<<" "<<v<<endl;
	if(u==v)return u;
	for(int i=K;i>=0;i--){
		if(f[u][i]!=f[v][i]){
			u=f[u][i];
			v=f[v][i];
		}
	}
	return f[u][0];
}

int getdep(int l,int r){
	int k=lg2[r-l+1];
	return dep[getlca(g[l][k],g[r-(1<<k)+1][k])];
}

int main(){
	freopen("query.in","r",stdin);
	freopen("query.out","w",stdout);
	scanf("%d",&n);
	K=log2(n);
	for(int i=1;i<n;i++){
		int u,v;scanf("%d%d",&u,&v);
		add(u,v);add(v,u);
	} 
	dfs(1,0);
	for(int i=1;i<=n;i++){
		lg2[i]=log2(i);
	}
	for(int j=1;j<=K;j++){
		for(int i=1;i<=n;i++){
			f[i][j]=f[f[i][j-1]][j-1];
		//	cout<<i<<" "<<j<<" "<<f[i][j]<<" "<<f[i][j-1]<<" "<<endl;
		}
	}
	for(int i=1;i<=n;i++){
		g[i][0]=i;
	}
	for(int j=1;j<=K;j++){
		for(int i=1;i+(1<<j)-1<=n;i++){
			g[i][j]=getlca(g[i][j-1],g[i+(1<<(j-1))][j-1]);
		}
	}
	scanf("%d",&q);
	while(q--){
		int l,r,k;scanf("%d%d%d",&l,&r,&k);
		int ans=0;
		for(int i=l;i+k-1<=r;i++){
			int j=i+k-1;
			ans=max(ans,getdep(i,j));
		}
		printf("%d\n",ans);
	}
	return 0;
}
