#include <iostream>
#include <vector>
#define endl '\n' 
const int maxn=1000010;
using namespace std;
int n, q, depm;
vector<int> E[maxn];
int dep[maxn], fa[25][maxn];
void dfs(int u, int f){
	dep[u]=dep[f]+1;
	fa[0][u]=f;
	for (auto v:E[u]){
		if (v==f) continue;
		dfs(v, u);
	}
}
int LCA(int a, int b){
	if (dep[a]<dep[b]) swap(a, b);
	for (int i=20; i>=0; i--){
		if (dep[a]-(1<<i)>=dep[b]){
			a=fa[i][a];
		}
	}
	if (a==b) return a;
	for (int i=20; i>=0; i--){
		if (fa[i][a]!=fa[i][b]){
			a=fa[i][a]; b=fa[i][b];
		}
	}
	return fa[0][a];
}
int main(void){
	freopen("query.in", "r", stdin);
	freopen("query.out", "w", stdout);
	cin.tie(0);
	cout.tie(0);
	cin>>n;
	for (int i=1, u, v; i<n; i++){
		cin>>u>>v;
		E[u].push_back(v);
		E[v].push_back(u);
	}
	dfs(1,1);
	for (int i=1; i<=20; i++){
		for (int j=1; j<=n; j++){
			fa[i][j]=fa[i-1][fa[i-1][j]];
		}
	}
	cin>>q;
	for (int i=1, l, r, k; i<=q; i++){
		depm=0;
		cin>>l>>r>>k;
		for (; l+k-1<=r; l++){
			int lca=l;
			for (int j=l+1; j<=l+k-1; j++){
//				cout<<lca<<" "<<j<<endl;
				lca=LCA(j, lca);
//				cout<<lca<<" ";
			}
//			cout<<endl;
			depm=max(depm, dep[lca]);
			
		}
		cout<<depm<<endl;
	}
}
