#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define dec(i,a,b) for(int i=a;i>=b;i--)
using namespace std;
typedef long long LL;
const int N=5e5+5;
int n,q,fa[N][21],dep[N],lca[21][N],p[N];
struct qh{
	int v,nt;
}E[N<<1];
inline void add(int u,int v){E[++p[0]]=(qh){v,p[u]};p[u]=p[0];return ;}
inline int Rd(){
	int s=0,w=1;char ch=getchar();
	while (ch<'0'||ch>'9'){if(ch=='-') w=-1;ch=getchar();}
	while (ch>='0'&&ch<='9') s=(s<<1)+(s<<3)+ch-'0',ch=getchar();
	return s*w;
}
void dfs(int u,int f){
	fa[u][0]=f;dep[u]=dep[f]+1;
	rep(i,1,20) fa[u][i]=fa[fa[u][i-1]][i-1];
	for(int i=p[u];i;i=E[i].nt){
		int v=E[i].v;
		if(v==f) continue;
		dfs(v,u);
	}
	return ;
}
int LCA(int x,int y){
	if(dep[x]<dep[y]) swap(x,y);
	dec(i,20,0) if(dep[fa[x][i]]>=dep[y]) x=fa[x][i];
	if(x==y) return x;
	dec(i,20,0) if(fa[x][i]!=fa[y][i]) x=fa[x][i],y=fa[y][i];
	return fa[x][0];
}
int Query(int l,int r){
	int t=log2(r-l+1);
	return dep[LCA(lca[t][l],lca[t][r-(1<<t)+1])];
}
int main(){
	freopen("query.in","r",stdin);
	freopen("query.out","w",stdout);
	n=Rd();
	rep(i,1,n-1){
		int u=Rd(),v=Rd();
		add(u,v);add(v,u);
	}
	dfs(1,0);
	rep(i,1,n) lca[0][i]=i;
	rep(j,1,20){
		for(int i=1;i+(1<<j)-1<=n;i++){
			lca[j][i]=LCA(lca[j-1][i],lca[j-1][i+(1<<(j-1))]);
//			printf("%d %d %d\n",j,i,lca[j][i]);
		}
	}
	q=Rd();
	rep(_,1,q){
		int l=Rd(),r=Rd(),k=Rd(),ans=1;
		rep(i,l,r-k+1) ans=max(ans,Query(i,i+k-1));
		printf("%d\n",ans);
	}
	return 0;
}
//don't forget me.
