#include<bits/stdc++.h>
using namespace std;

const int N = 5e5 + 10; 
int n, q, lg[N];
int dep[N], f[N][21], st[N][21];
int id, head[N << 1], nxt[N << 1], to[N << 1];

void add(int u, int v){
	to[++id] = v;
	nxt[id] = head[u], head[u] = id;
}

void dfs(int u, int p){
	f[u][0] = p;
	for(int i=1;i<=20;i++)
		f[u][i] = f[f[u][i - 1]][i - 1];
	for(int i=head[u];i;i=nxt[i]){
		int v = to[i];
		if(v == p)
			continue;
		dep[v] = dep[u] + 1;
		dfs(v, u);
	}
}

int LCA(int u, int v){
	if(dep[u] < dep[v])
		swap(u, v);
	for(int i=20;~i;i--)
		if(dep[f[u][i]] >= dep[v])
			u = f[u][i];
	if(u == v)
		return u;
	for(int i=20;~i;i--)
		if(f[u][i] != f[v][i])
			u = f[u][i], v = f[v][i];
	return f[u][0];
}

void init(){
	lg[0] = -1;
	for(int i=1;i<=n;i++){
		st[i][0] = i;
		lg[i] = lg[i >> 1] + 1;
	}
	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]);
}

int query(int l, int r){
	int k = lg[r - l + 1];
	return LCA(st[l][k], st[r - (1 << k) + 1][k]);
}

int main(){
	freopen("query.in", "r", stdin);
	freopen("query.out", "w", stdout);
	scanf("%d", &n);
	for(int i=1,u,v;i<n;i++){
		scanf("%d%d", &u, &v);
		add(u, v), add(v, u);
	}
	dep[1] = 1;
	dfs(1, 1);
	init();
	scanf("%d", &q);
	while(q--){
		int l, r, k, res = 0;
		scanf("%d%d%d", &l, &r, &k);
		for(int i=l;i<=r-k+1;i++){
//			printf("[%d, %d]: %d\n", i, i + k - 1, query(i, i + k - 1));
			res = max(res, dep[query(i, i + k - 1)]);
		}
		printf("%d\n", res);
	}
	return 0;
}
/*
6
5 6
6 1
6 2
2 3
2 4
3
2 5 2
1 4 1
1 6 3

*/ 
