#include<bits/stdc++.h>

using namespace std;

const int MAXN = 5e5 + 10;
bool vis[MAXN];
vector<unsigned int> g[MAXN];
unsigned int fa[MAXN], dep[MAXN];
int n;

void dfs(int u, int p) {
	fa[u] = p;dep[u] = dep[p]+1;vis[u] = true;
	//printf("u:%d %d %d\n", u, fa[u], dep[u]);
	for(auto v: g[u]) {
		if(!vis[v]) {
			dfs(v, u);
		}
	}
}

int LCA(int u, int v) {
	//if(mp[make_pair(u, v)]) {
		//return mp[make_pair(u, v)];
	//}
	int x = u, y = v;
	while(dep[u] > dep[v]) {
		u = fa[u];
	}
	while(dep[v] > dep[u]) {
		v = fa[v];
	}
	while(u != v) {
		u = fa[u];v = fa[v];
	}
	//mp[make_pair(x, y)] = dep[u];
	//cout << "u:" << u << " dep:" << dep[u] << '\n';
	return dep[u];
}

int main() {
	freopen("query.in", "r", stdin);
	freopen("query.out", "w", stdout);
	cin >> n;
	for(int i = 1; i < n; i++) {
		unsigned int u, v;
		cin >> u >> v;
		//printf("i:%d %d %d\n", i, u, v);
		g[u].push_back(v);//printf("test:%d--", i*2-1); 
		g[v].push_back(u);//printf("text:%d\n", i*2);
	}
	//printf("text\n");
	dep[1] = 1;
	dfs(1, 0);
	int q;
	cin >> q;
	while(q--) {
		int l, r, k;
		cin >> l >> r >> k;
		int ans = 0;
		for(int i = l; i+k-1 <= r; i++) {
			//cout << ans << " i:" << i << " j:" << i+k-1 << ":" << LCA(i, i+k-1) << ' ' << dep[i] << ' ' << dep[i+k-1] << '\n';
			
			ans = max(ans, LCA(i, i+k-1) );
		}
		cout << ans << '\n';
	}
	
	return 0;
}
