#include<bits/stdc++.h>

using namespace std;

const int N=5e5+10;

int n,q;
vector<int> G[N];
int fa[N],siz[N],dep[N],top[N];

void dfs1(int u,int father){
	fa[u]=father,siz[u]=1,dep[u]=dep[fa[u]]+1;
	for(auto v:G[u]) if(v!=fa[u]) dfs1(v,u),siz[u]+=siz[v];
}
void dfs2(int u,int fir){
	top[u]=fir;
	int hson=0;
	for(auto v:G[u]) if(v!=fa[u]) if(siz[hson]<siz[v]) hson=v;
	if(hson) dfs2(hson,fir);
	for(auto v:G[u]) if(v!=fa[u]&&v!=hson) dfs2(v,v);
}
int lca(int u,int v){
	if(u==0||v==0) return u|v;
	while(top[u]!=top[v]){
		if(dep[top[u]]>dep[top[v]]) u=fa[top[u]];
		else v=fa[top[v]];
	}
	return dep[u]<dep[v]?u:v;
}

struct zkw_seg{
	int bit,t[N<<2];
	void build(int n){
		for(bit=1;bit<=n;bit<<=1);bit--;
		for(int i=1;i<=n;i++) t[i+bit]=i;
		for(int i=bit;i;i--) t[i]=lca(t[i<<1],t[i<<1|1]);
	}
	int qry(int l,int r){
		int res=0;
		for(l+=bit-1,r+=bit+1;l^r^1;l>>=1,r>>=1){
			if(~l&1) res=lca(res,t[l^1]);
			if(r&1) res=lca(res,t[r^1]);
		}
		return dep[res];
	}
}Seg;

void sol(){
	int l,r,k;
	scanf("%d %d %d",&l,&r,&k);
	int ans=0;
	for(int i=l;i+k-1<=r;i++) ans=max(ans,Seg.qry(i,i+k-1));
	printf("%d\n",ans);
}

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);
		G[u].push_back(v),G[v].push_back(u);
	}
	dfs1(1,0);
	dfs2(1,1);
	Seg.build(n);
	scanf("%d",&q);
	while(q--) sol();
	return 0;
}
