#include<bits/stdc++.h>
#define up(i, a, b) for(int i = (int)a; i <= (int)b; ++i)
#define dn(i, a, b) for(int i = (int)a; i >= (int)b; --i)
#define vc vector
#define pb push_back

using namespace std;

const int MN = 5e5 + 5;

int n, Q;
vc<int> v[MN];
int dfn[MN], p[MN], tc;
int f[21][MN], g[21][MN], dep[MN], fa[21][MN], qwq;
int lg[MN];

void dfs(int x){
	dep[x] = dep[fa[0][x]] + 1;
	qwq = max(qwq, lg[dep[x]] + 1);
	for(int j = 1; (1 << j) < dep[x]; ++j) fa[j][x] = fa[j - 1][fa[j - 1][x]];
	dfn[x] = ++tc; p[tc] = x; g[0][x] = f[0][x] = tc;
	for(int y : v[x]){
		if(y == fa[0][x]) continue;
		fa[0][y] = x;
		dfs(y);
	}
}
int lca(int x, int y){
	if(dep[x] < dep[y]) swap(x, y);
	dn(k, qwq, 0) if(dep[fa[k][x]] >= dep[y]) x = fa[k][x];
	if(x == y) return x;
	dn(k, qwq, 0) if(fa[k][x] != fa[k][y]) x = fa[k][x], y = fa[k][y];
	return fa[0][x];
}
int query1(int l, int r){
	int k = lg[r - l + 1];
	return max(f[k][l], f[k][r - (1 << k) + 1]);
}
int query2(int l, int r){
	int k = lg[r - l + 1];
	return min(g[k][l], g[k][r - (1 << k) + 1]);
}

signed main(){
	freopen("query.in", "r", stdin);
	freopen("query.out", "w", stdout);
	scanf("%d", &n);
	up(i, 2, n) lg[i] = lg[i >> 1] + 1;
	qwq = lg[n] + 1;
	up(i, 1, n - 1){
		int x, y; scanf("%d%d", &x, &y);
		v[x].pb(y), v[y].pb(x);
	}
	dfs(1);
	cin >> Q;
	up(j, 1, qwq) up(i, 1, n) f[j][i] = max(f[j - 1][i], f[j - 1][i + (1 << j - 1)]);
	up(j, 1, qwq) up(i, 1, n) g[j][i] = min(g[j - 1][i], g[j - 1][i + (1 << j - 1)]);
	int c = 0;
	while(Q--){
		int l, r, k; scanf("%d%d%d", &l, &r, &k);
		int ans = 0;
//		cerr << (r - k + 1) - l + 1 << endl;
		up(i, l, r - k + 1){
			int a1 = query1(i, i + k - 1);
			int a2 = query2(i, i + k - 1);
			ans = max(ans, dep[lca(p[a1], p[a2])]);
		}
		printf("%d\n", ans);
	}
//	cerr << "FK: " << c;
	
	return 0;
}
