#include<bits/stdc++.h>
using namespace std;
vector<int> g[500050];
int n;
int fa[500050][20];
int dep[500050];
int md;
void dfs(int u,int f){
//	cout<<u<<endl; 
	fa[u][0] = f;
	dep[u] = dep[f]+1;
	md = max(md,dep[u]);
	for(int i = 1;i <= 19;i++){
		fa[u][i] = fa[fa[u][i-1]][i-1];
	}
	for(int v:g[u]){
		if(v == f)continue;
		dfs(v,u);
	}
}
int lca(int u,int v){
	if(dep[u] < dep[v])swap(u,v);
	for(int i = 19;i >= 0;i--){
		if(dep[fa[u][i]] >= dep[v]){
			u = fa[u][i];
		}
	}
	if(u == v)return u;
	for(int i = 19;i >= 0;i--){
		if(fa[u][i] != fa[v][i]){
			u =fa[u][i];
			v = fa[v][i];
		}
	}
	return fa[u][0];
}
int gr(int l,int r){
	int res = l;
	for(int i = l+1;i <= r;i++){
		res = lca(res,i);
	} 
	return res;
} 
int main(){
	freopen("query.in","r",stdin);
	freopen("query.out","w",stdout);
	ios::sync_with_stdio(0); 
	cin>>n;
	for(int i = 1;i<=n-1;i++){
		int u,v;
		cin>>u>>v;
		g[u].push_back(v);
		g[v].push_back(u);
	} 
	dfs(1,0);
	int q;
	cin>>q;
	while(q--){
		int l,r,k;
		cin>>l>>r>>k;
		int ans = 0;
		for(int L = l,R = L+k-1;R <= r;L++,R++){
			ans = max(ans,dep[gr(L,R)]);
		}
		cout<<ans<<endl;
	}
	return 0;
} 
