#include<bits/stdc++.h>
using namespace std;
//#define int long long
const int N=5e5+5,mod=1e9+7; 
int read(){
	int num=0,typ=1,c=getchar();
	while('0'>c||c>'9'){
		if(c=='-') typ=-1;
		c=getchar();
	}while('0'<=c&&c<='9'){
		num=num*10+c-48;
		c=getchar(); 
	}return num*typ;
}
int n,q;
int head[N],nxt[N<<1],to[N<<1],tot;
int fa[N],siz[N],dep[N],son[N],top[N];
int lc[N][20];
void edge(int x,int y){
	to[++tot]=y;
	nxt[tot]=head[x];
	head[x]=tot;
}
void dfs1(int u,int f){
	fa[u]=f;siz[u]=1;dep[u]=dep[f]+1;
	for(int i=head[u];i;i=nxt[i]){
		int v=to[i];
		if(v==f) continue;
		dfs1(v,u);
		siz[u]+=siz[v];
		if(siz[v]>siz[son[u]]) son[u]=v;
	}
}
void dfs2(int u,int t){
	top[u]=t;
	if(son[u]) dfs2(son[u],t);
	for(int i=head[u];i;i=nxt[i]){
		int v=to[i];
		if(v==fa[u]||v==son[u]) continue;
		dfs2(v,v);
	}
}
int lca(int x,int y){
	while(top[x]!=top[y]){
		if(dep[top[x]]>dep[top[y]]) x=fa[top[x]];
		else y=fa[top[y]];
	}return dep[x]<dep[y]?x:y; 
}
int query(int l,int r){
	int ans=l;
	for(int j=19;~j;j--){
		if(l+(1<<j)-1>r) continue;
		ans=lca(ans,lc[l][j]);
		l+=(1<<j);
	}return ans;
}
bool spea=1;
int main(){
	freopen("query.in","r",stdin);
	freopen("query.out","w",stdout);
	n=read();
	for(int i=1;i<n;i++){
		int u=read(),v=read();
		edge(u,v);
		edge(v,u);
	}
	dfs1(1,0);
	dfs2(1,1);
	for(int i=1;i<=n;i++){
		if(top[i]!=1) spea=0;
	}
	for(int i=1;i<=n;i++){
		lc[i][0]=i;
	}
	for(int j=1;j<=19;j++){
		for(int i=1;i+(1<<(j-1))<=n;i++){
			lc[i][j]=lca(lc[i][j-1],lc[i+(1<<(j-1))][j-1]);
		}
	}
	q=read();
	for(int i=1;i<=q;i++){
		int l=read(),r=read(),k=read();
		int ans=0; 
		for(int j=l;j+k-1<=r;j++){
			ans=max(ans,dep[query(j,j+k-1)]); 
		}
		printf("%d\n",ans);
	}
	return 0;
}
