#include<bits/stdc++.h>
#define getmid int mid=(l+r)>>1
#define ls (i<<1)
#define rs (i<<1|1)
using namespace std;
const int N=5e5+5;
int n,q,fa[N],son[N],dep[N],siz[N],top[N],dfn[N],idd[N],dfncnt;
int tre[N<<2];
vector<int>G[N];
void dfs1(int u){
	son[u]=-1,siz[u]=1;
	for(int v:G[u])
		if(v!=fa[u]){
			fa[v]=u,dep[v]=dep[u]+1;
			dfs1(v);
			siz[u]+=siz[v];
			if(son[u]==-1||siz[v]>siz[son[u]]) son[u]=v;
		}
}
void dfs2(int u,int t){
	dfn[u]=++dfncnt,idd[dfncnt]=u,top[u]=t;
	if(son[u]==-1) return;
	dfs2(son[u],t);
	for(int v:G[u])
		if(v!=fa[u]&&v!=son[u]) dfs2(v,v);
}
int getlca(int a,int b){
	while(top[a]!=top[b])
		if(dep[top[a]]>dep[top[b]]) a=fa[top[a]];
		else b=fa[top[b]];
	if(dep[a]>dep[b]) swap(a,b);
	return a;
}
void build(int l=1,int r=n,int i=1){
	if(l==r){
		tre[i]=l;
		return;
	}
	getmid;
	build(l,mid,ls);
	build(mid+1,r,rs);
	tre[i]=getlca(tre[ls],tre[rs]);
}
int query(int a,int b,int l=1,int r=n,int i=1){
	if(a<=l&&r<=b) return tre[i];
	getmid;
	if(a<=mid&&mid+1<=b) return getlca(query(a,b,l,mid,ls),query(a,b,mid+1,r,rs));
	if(a<=mid) return query(a,b,l,mid,ls);
	if(mid+1<=b) return query(a,b,mid+1,r,rs);
}
int main(){
	freopen("query.in","r",stdin);
	freopen("query.out","w",stdout);
	ios::sync_with_stdio(false),cin.tie(0),cout.tie(0);
	cin>>n;
	for(int i=1,u,v;i<n;i++) cin>>u>>v,G[u].push_back(v),G[v].push_back(u);
	dep[1]=1;
	dfs1(1);
	dfs2(1,1);
	build();
	cin>>q;
	while(q--){
		int l,r,k,ans=0;
		cin>>l>>r>>k;
		for(int i=l,j=i+k-1;j<=r;i++,j++){
			int cur=query(i,j);
			ans=max(ans,dep[cur]);
		}
		cout<<ans<<"\n";
	}
	return 0;
}
