#include<bits/stdc++.h>
#define pii pair<int, int>
#define F first
#define S second
#define ll long long
#define vc vector
#define vci vc<int>
#define psb push_back
using namespace std;
ll md;
inline ll ksm(ll a, ll b, ll md){
	ll ans = 1;
	while(b){
		if(b & 1) ans = ans * a % md;
		a = a * a % md;
		b >>= 1;
	}
	return ans;
}
inline ll read(){
	ll ans = 0;
	bool fl = 0;
	char c;
	while(1){
		c = getchar();
		if(c == '-' || ('0' <= c && c <= '9')) break;
	}
	if(c == '-') fl = 1;
	else ans = (int)(c - '0');
	while(1){
		c = getchar();
		if(c < '0' || c > '9') break;
		ans = (ans << 3) + (ans << 1);
		ans += (int)(c - '0');
	}
	if(fl) ans = ans * -1;
	return ans;
}
vci g[500005];
int f[500005][25], d[500005];
int n, q, st[500005][25], tlg[500005];
void dfs(int u, int ft, int dt){
	d[u] = dt, f[u][0] = ft;
	for(int i = 1; i <= 20; i++) f[u][i] = f[f[u][i - 1]][i - 1];
	for(int v : g[u]){
		if(ft == v) continue;
		dfs(v, u, dt + 1);
	}
}
int lca(int a, int b){
	if(d[a] < d[b]) swap(a, b);
	for(int i = 20; i >= 0; i--)
		if(d[f[a][i]] >= d[b]) a = f[a][i];
	if(a == b) return a;
	for(int i = 20; i >= 0; i--)
		if(f[a][i] != f[b][i]) a = f[a][i], b = f[b][i];
	return f[a][0];
}
int get(int l, int r){
	return lca(st[l][tlg[r - l + 1]], st[r - (1 << tlg[r - l + 1]) + 1][tlg[r - l + 1]]);
}
int main(){
	freopen("query.in", "r", stdin);
	freopen("query.out", "w", stdout);
	tlg[1] = 0;
	cin >> n;
	for(int i = 2; i <= n; i++) tlg[i] = tlg[i / 2] + 1;
	for(int i = 1, a, b; i < n; i++){
		cin >> a >> b;
		g[a].psb(b);
		g[b].psb(a);
	}
	dfs(1, 0, 1);
	for(int i = 1; i <= n; i++) st[i][0] = i;
	for(int j = 1; j <= 20; j++)
		for(int i = 1; i + (1 << j) - 1 <= n; i++) st[i][j] = lca(st[i][j - 1], st[i + (1 << (j - 1))][j - 1]);
	cin >> q;
	while(q--){
		int l, r, k, ans = 0;
		cin >> l >> r >> k;
		for(int i = l; i + k - 1 <= r; i++){
			ans = max(ans, d[get(i, i + k - 1)]);
//			cout << i << ' ' << get(i, i + k - 1) << endl;
		}
		cout << ans << endl;
	}
	return 0;
}
