#include <bits/stdc++.h>
using namespace std;
constexpr int N=5e5+1; 
int n;
vector<int> e[N];
int fa[20][N],dep[N];
void dfs_init(int u,int f){
	dep[u]=dep[f]+1;
	for (auto &v:e[u])
		if (v!=f)
			fa[0][v]=u,dfs_init(v,u);
}
void get_fa(){
	for (int i=1;i<20;i++)
		for (int j=1;j<=n;j++)
			fa[i][j]=fa[i-1][fa[i-1][j]];
}
int lca(int u,int v){
	if (dep[u]<dep[v])swap(u,v);
	for (int i=19;i>=0;i--)
		if (dep[fa[i][u]]>=dep[v])
			u=fa[i][u];
	if (u==v)
		return u;
	for (int i=19;i>=0;i--)
		if (fa[i][u]!=fa[i][v])
			u=fa[i][u],v=fa[i][v];
	return fa[0][u];
}
void init(){
	cin>>n;
	memset(fa,0,sizeof(fa));
	memset(dep,0,sizeof(dep));
	for (int i=1;i<=n;i++)
		e[i].clear();
	for (int i=1,u,v;i<n;i++)
		cin>>u>>v,e[u].push_back(v),e[v].push_back(u);
	dfs_init(1,0);
}
void solve(){
	int q;cin>>q;
	while (q--){
		int l,r,kk;
		cin>>l>>r>>kk;
		int ans=0;
		for (int k=kk;k<=r-l+1;k++)
		for (int i=l;i+k-1<=r;i++){
			int tmp=i;
			for (int j=i+1;j<i+k;j++){
				tmp=lca(tmp,j);
			}
			ans=max(ans,dep[tmp]);
		}
		cout<<ans<<'\n';
	}
}
int main(){
	freopen("query.in","r",stdin);
	freopen("query.out","w",stdout);
	cin.tie(0),cout.tie(0)->sync_with_stdio(0);
	init();
	solve();
}

