#include<iostream>
#include<cstdio>
#include<queue>
#include<algorithm>
using namespace std;
const int N=5e5+5;
vector<int>g[N];
int fa[N],top[N],sz[N],zs[N],dep[N],dfn[N],antidfn[N];
void dfs1(int fat,int u,int dp){
	sz[u]=1;
	fa[u]=fat;
	dep[u]=dp;
	int maxn=0;
	for(int i=0;i<g[u].size();i++){
		int v=g[u][i];
		if(v==fat)continue;
		dfs1(u,v,dp+1);
		if(sz[v]>maxn){
			maxn=zs[v];
			zs[u]=v;
		}
		sz[u]+=sz[v];
	}
	return ;
}
int cnt=0;
void dfs2(int tp,int u){
	top[u]=tp;
	++cnt;
	dfn[u]=cnt;
	antidfn[cnt]=u;
	if(!zs[u])return ;
	dfs2(tp,zs[u]);
	for(int i=0;i<g[u].size();i++){
		int v=g[u][i];
		if(v==fa[u]||v==zs[u])continue;
		dfs2(v,v);
	}
	return ;
}
//int k=0;
int lca(int u,int v){
	while(top[u]!=top[v]){
		if(dep[u]<dep[v])swap(u,v);
		if(zs[fa[u]]==u)u=fa[u];
		else u=fa[top[u]];
	}
//	k=min(dep[u],dep[v]);
	if(dep[u]<dep[v])return u;
	else return v;
}
int main(){
	freopen("query.in","r",stdin);
	freopen("query.out","w",stdout);
	int n;
	cin>>n;
	for(int i=1;i<=n-1;i++){
		int u,v;
		scanf("%d %d",&u,&v);
		g[u].push_back(v);
		g[v].push_back(u);
	}
	dfs1(1,1,1);
	dfs2(1,1);
	int q;
	cin>>q;
	while(q--){
		int l,r,k;
		scanf("%d %d %d",&l,&r,&k);
		int ans=0;
		for(int i=l;i<=r-k+1;i++){
			int cnt=i;
			for(int j=i+1;j<=i+k-1;j++){
//				cout<<i<<" "<<j<<" \n";
//				cout<<cnt<<" "<<j<<" LCA:"<<lca(cnt,j)<<" kkk\n";
				cnt=lca(cnt,j);
			}
			
			ans=max(ans,dep[cnt]);
		}
		cout<<ans<<"\n";
	}
	return 0;
}
