#include<bits/stdc++.h>
using namespace std;
const int N=500005,LOG=20;
vector<int>edge[N];
int n,q;
int depth[N],ancestor[N][LOG];
void dfs(int node,int parent){
	depth[node]=depth[parent]+1;
	ancestor[node][0]=parent;
	for(int i=1;i<LOG;i++){
		ancestor[node][i]=ancestor[ancestor[parent][i-1]][i-1];
	}
	for(int v:edge[node]){
		if(parent!=v)dfs(v,node);
	}
}
int lca(int u,int v){
	if(depth[u]<depth[v])swap(u,v);
	for(int i=LOG-1;i>=0;i--){
		if(depth[u]-(1<<i)>=depth[v]){
			u=ancestor[u][i];
		}
	}
	if(u==v)return u;
	for(int i=LOG-1;i>0;i--){
		if(ancestor[u][i]!=ancestor[v][i]){
			u=ancestor[u][i];
			v=ancestor[v][i];
		}
	}
	return ancestor[u][0];
}
int _lca(int l,int r){
	int zlca=l;
	for(int i=l+1;i<=r;i++)zlca=lca(zlca,i);
	return zlca;
}
int main(){
	freopen("query.in","r",stdin);
	freopen("query.out","w",stdout);
	scanf("%d",&n);
	for(int i=1;i<n;i++){
		int u,v;
		scanf("%d%d",&u,&v);
		edge[u].emplace_back(v);
		edge[v].emplace_back(u);
	}
	depth[0]=0;
	dfs(1,0);
	scanf("%d",&q);
	while(q--){
		int ans=1,l,r,k;
		scanf("%d%d%d",&l,&r,&k);
		for(int i=l;i<=r;i++){
			for(int j=i+k-1;j<=r;j++){
				ans=max(ans,depth[_lca(i,j)]);
			}
		}
		printf("%d\n",ans);
	}
	return 0;
}
