#include<bits/stdc++.h>

using namespace std;

#define M 500005

int n,q;
int head[M],tot;
struct edge{
	int nxt,to;
}e[M<<1];

void add(int u,int v){
	e[++tot]=(edge){head[u],v};
	head[u]=tot;
}

int dep[M],hson[M],siz[M],fa[M];
int top[M];

void dfs1(int u,int f,int pos){
	dep[u]=pos;
	hson[u]=-1;
	siz[u]=1;
	fa[u]=f;
	for(int i=head[u];i;i=e[i].nxt){
		int v=e[i].to;
		if(v==f) continue;
		dfs1(v,u,pos+1);
		siz[u]+=siz[v];
		if(!~hson[u] || siz[hson[u]]<siz[v]) hson[u]=v;
	}
}

void dfs2(int u,int tp){
	top[u]=tp;
	if(!~hson[u]) return;
	dfs2(hson[u],tp);
	for(int i=head[u];i;i=e[i].nxt){
		int v=e[i].to;
		if(v==fa[u] || v==hson[u]) continue;
		dfs2(v,v);
	}
}

int lca(int u,int v){
	while(top[u]!=top[v]){
		if(dep[top[u]]<dep[top[v]]) swap(u,v);
		u=fa[top[u]];
	}
	if(dep[u]>dep[v]) return v;
	return u;
}

int st[M][20],L[M];

void init(){
	L[0]=-1;
	for(int i=1;i<=n;++i) st[i][0]=i,L[i]=L[i>>1]+1;
	for(int j=1;j<20;++j){
		for(int i=1;i+(1<<j)-1<=n;++i){
			st[i][j]=lca(st[i][j-1],st[i+(1<<(j-1))][j-1]);
		}
	}
}

int query(int l,int r){
	int k=L[r-l+1];
	return lca(st[l][k],st[r-(1<<k)+1][k]);
}

int main(){
	freopen("query.in","r",stdin);
	freopen("query.out","w",stdout);
	scanf("%d",&n);
	for(int i=1,u,v;i<n;++i) scanf("%d %d",&u,&v),add(u,v),add(v,u);
	dfs1(1,0,1);
	dfs2(1,1);
	init();
	scanf("%d",&q);
	while(q--){
		int l,r,k;
		scanf("%d %d %d",&l,&r,&k);
		int res=0;
		for(int i=l;i<=r-k+1;++i) res=max(res,dep[query(i,i+k-1)]);
		printf("%d\n",res);
	}
	return 0;
}
