#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
const int N = 5e5 + 10;
int ver[2 * N], nxt[2 * N], head[N], tot;
void add(int x, int y){
	ver[++tot] = y;
	nxt[tot] = head[x];
	head[x] = tot;
}
int n, q;
int fa[N][20], d[N];
void dfs1(int x, int ff){
	fa[x][0] = ff, d[x] = d[ff] + 1;
	for(int i = 1; i <= 19; i++) fa[x][i] = fa[fa[x][i-1]][i-1];
	for(int i = head[x]; i; i = nxt[i]){
		int y = ver[i];
		if(y == ff) continue;
		dfs1(y, x); 
	}
}
int lca(int x, int y){
//	printf("x = %d, y = %d:", x, y);
	if(d[x] < d[y]) swap(x, y);
	for(int i = 19; i >= 0; i--)
		if(d[fa[x][i]] >= d[y])
			x = fa[x][i];
	
	if(x == y){
//		printf("!%d\n", x);
		return x;
	}
	for(int i = 19; i >= 0; i--)
		if(fa[x][i] != fa[y][i])
			x = fa[x][i], y = fa[y][i];
//	printf("@%d\n", fa[x][0]);
	return fa[x][0];
}
int la(int l, int r){
	if(l == r) return d[l];
	int lcaa = lca(l, l+1);
	for(int i = l+2; i <= r; i++){
		lcaa = lca(lcaa, i);
		if(lcaa == 1) return 1;
	}
	return d[lcaa]; 
}
int ask(int l, int r, int k){
	int ans = 1;
	for(int i = l; i + k - 1 <= r; i++)
		ans = max(ans, la(i, i+k-1));
	return ans;
}
int main(){
	freopen("query.in", "r", stdin);
	freopen("query.out", "w", stdout);
	scanf("%d", &n);
	for(int i = 1; i <= n-1; i++){
		int u, v;scanf("%d%d", &u, &v);
		add(u, v), add(v, u);
	}
	dfs1(1, 0);
//	for(int i = 1; i <= n; i++) printf("d[%d] = %d\n", i, d[i]);
	scanf("%d", &q);
	for(int i = 1; i <= q; i++){
		int l, r, k; scanf("%d%d%d", &l, &r, &k);
		printf("%d\n", ask(l, r, k));
//		if(i == 52) printf("%d %d %d\n", l, r, k);
	}
	return 0;
}
