#include<bits/stdc++.h>
using namespace std;

const int N = 5e5 + 5;
int n, m, u, v, d[N], l, r, k;
int fa[N][20];
vector<int> to[N];

inline void dfs(int u, int pa){
	d[u] = d[pa] + 1;
	fa[u][0] = pa;
	for(int i = 1; i < 20; ++i) fa[u][i] = fa[fa[u][i - 1]][i - 1];
	for(auto v : to[u]) if(v ^ pa) dfs(v, u);
}
inline int lca(int x, int y){
	if(d[x] < d[y]) swap(x, y);
	for(int i = 19; ~i; --i) if(d[fa[x][i]] >= d[y]) x = fa[x][i];
	if(x == y) return x;
	for(int i = 19; ~i; --i) if(fa[x][i] ^ fa[y][i]) x = fa[x][i], y = fa[y][i];
	return fa[x][0];
}
signed main(){
//	system("fc query.out query2.ans");
	freopen("query.in", "r", stdin);
	freopen("query.out", "w", stdout);
	cin >> n;
	for(int i = 1; i < n; ++i) scanf("%d%d", &u, &v), to[u].push_back(v), to[v].push_back(u);
	cin >> m;
	
	dfs(1, 0);
	while(m--){
		scanf("%d%d%d", &l, &r, &k);
		int mx = 0;
		for(int i = l; i <= r - k + 1; ++i){
			int Lca = i; 
			for(int j = i; j <= r; ++j){
				Lca = lca(Lca, j);
				if(d[Lca] < mx) break; 
				if(j - i + 1 >= k) mx = d[Lca];
			}
		}
		printf("%d\n", mx);
	}
	return 0;
}
