#include<bits/stdc++.h>
#define endl '\n'
using namespace std;
typedef long long ll;
const int N = 5e5 + 5;
int n, q, deg[N], dep[N];
int f[N][25];
vector<int> G[N];
void dfs(int u, int fa){
	dep[u] = dep[fa] + 1;
	f[u][0] = fa;
	for(int i = 1; i <= 20; ++i) f[u][i] = f[f[u][i - 1]][i - 1];
	for(auto v : G[u])
		if(v != fa) dfs(v, u);
}
int lca(int u, int v){
	if(dep[v] > dep[u]) swap(u, v);
	for(int i = 20; i >= 0; --i)
		if(dep[f[u][i]] >= dep[v]) u = f[u][i];
	if(u == v) return u;
	for(int i = 20; i >= 0; --i)
		if(f[u][i] != f[v][i]) u = f[u][i], v = f[v][i];
	return f[u][0];
}
int st[N][25];
int query(int l, int r){
	int k = log2(r - l + 1);
	return lca(st[l][k], st[r - (1 << k) + 1][k]);
}
void solve1(){
	dfs(1, 0);
	for(int i = 1; i <= n; ++i) st[i][0] = i;
	for(int j = 1; j <= 20; ++j)
		for(int i = 1; i <= n - (1 << j) + 1; ++i) st[i][j] = lca(st[i][j - 1], st[i + (1 << j - 1)][j - 1]);
	cin >> q;
	while(q--){
		int l, r, k;
		cin >> l >> r >> k;
		int ans = 0;
		for(int i = l; i <= r - k + 1; ++i) ans = max(ans, dep[query(i, i + k - 1)]);
		cout << ans << endl;
	}
}
int qry(int l, int r){
	int k = log2(r - l + 1);
	return min(st[l][k], st[r - (1 << k) + 1][k]);
}
void solve2(){
	dfs(1, 0);
	for(int i = 1; i <= n; ++i) st[i][0] = dep[i];
	for(int j = 1; j <= 20; ++j)
		for(int i = 1; i <= n - (1 << j) + 1; ++i) st[i][j] = min(st[i][j - 1], st[i + (1 << j - 1)][j - 1]);
	cin >> q;
	while(q--){
		int l, r, k;
		cin >> l >> r >> k;
		int ans = 0;
		for(int i = l; i <= r - k + 1; ++i) ans = max(ans, qry(i, i + k - 1));
		cout << ans << endl;
	}
}
void solve3(){
	dfs(1, 0);
	for(int i = 1; i <= n; ++i) st[i][0] = i;
	for(int j = 1; j <= 20; ++j)
		for(int i = 1; i <= n - (1 << j) + 1; ++i) st[i][j] = lca(st[i][j - 1], st[i + (1 << j - 1)][j - 1]);
	cin >> q;
	while(q--){
		int l, r, k;
		cin >> l >> r >> k;
		cout << dep[query(l, l + k - 1)] << endl;
	}
}
signed main(){
	freopen("query.in", "r", stdin);
	freopen("query.out", "w", stdout);
	ios::sync_with_stdio(false);
	cin.tie(0), cout.tie(0);
	cin >> n;
	int flg = 1;
	for(int i = 1, u, v; i < n; ++i){
		cin >> u >> v;
		G[u].push_back(v), G[v].push_back(u);
		deg[u]++, deg[v]++;
		if(deg[u] > 2 || deg[v] > 2) flg = 0;
	}
	if(n <= 5000 && q <= 5000) solve1();
	else if(flg) solve2();
	else solve3();
	return 0;
}
/*
6
5 6
6 1
6 2
2 3
2 4
3
2 5 2
1 4 1
1 6 3
*/
