#include<bits/stdc++.h>
using namespace std;
const int maxn = 5e5 + 5;
inline int read(){
	int ans = 0, flg = 1;
	char c = getchar();
	while(c < '0' || c > '9'){
		if(c == '-') flg = -flg;
		c = getchar();
	}
	while(c >= '0' && c <= '9'){
		ans = ans * 10 + c - '0';
		c = getchar();
	}
	return ans * flg;
}
int n, q;
vector<int> e[maxn];
int d[maxn], dep[maxn], fa[maxn][40];
int l[maxn], r[maxn], k[maxn];
bool checkA(){
	for(int i = 1; i <= n; i++){
		if(d[i] > 2){
			return false;
		}
	}
	return true;
}
void dfs(int x, int father){
	dep[x] = dep[father] + 1;
	fa[x][0] = father;
	for(int j = 1; j < 40; j++){
		fa[x][j] = fa[fa[x][j - 1]][j - 1];
	}
	for(int v : e[x]){
		if(v == father) continue;
		dfs(v, x);
	}
}
int lca(int x, int y){
	if(dep[x] < dep[y]) swap(x, y);
	for(int j = 39; j >= 0; j--){
		if(dep[fa[x][j]] >= dep[y]){
			x = fa[x][j];
		}
	}
	if(x == y) return x;
	for(int j = 39; j >= 0; j--){
		if(fa[x][j] != fa[y][j]){
			x = fa[x][j];
			y = fa[y][j];
		}
	}
	return fa[x][0];
}
bool flagB = true;
signed main(){
	freopen("query.in", "r", stdin);
	freopen("query.out", "w", stdout);
	n = read();
	for(int i = 1, u, v; i < n; i++){
		u = read(), v = read();
		d[u]++, d[v]++;
		e[u].push_back(v);
		e[v].push_back(u);
	}
	dfs(1, 0);
	q = read();
	for(int i = 1; i <= q; i++){
		l[i] = read(), r[i] = read(), k[i] = read();
		if(k[i] != (r[i] - l[i] + 1)) flagB = false;
	}
	if(flagB){
		for(int i = 1; i <= q; i++){
			if(l[i] == r[i]){
				cout << dep[l[i]] << "\n";
				continue;
			}
			int LCA = l[i];
			for(int i = l[i] + 1; i <= r[i]; i++){
				LCA = lca(LCA, i);
			}
			cout << dep[LCA] << "\n";
		}
		return 0;
	}
	for(int i = 1; i <= q; i++){
		int mx = -1;
		for(int j = l[i]; j <= r[i] - k[i] + 1; j++){
			int L = j, R = j + k[i] - 1;
			if(L == R){
				mx = max(mx, dep[L]);
				continue;
			}
			int LCA = L;
			for(int K = L + 1; K <= R; K++){
				LCA = lca(LCA, K);
			}
			mx = max(mx, dep[LCA]);
		}
		cout << mx << "\n";
	}
	return 0;
}
