#include<bits/stdc++.h>
using namespace std;
#define debug 0
int n, q;
vector<int>G[500003];
int dep[500003] = {}, dfn[500003], rdfn[500003], pos[500003];
int cnt = 0, m = 0;
int mlg[1000003] = {-1}, st[1000003][23], st2[500003][23];
void dfs(int v, int fa){
	dep[v] = dep[fa] + 1;
	dfn[v] = ++cnt;
	rdfn[cnt] = v;
	st[++m][0] = cnt;
	pos[cnt] = m;
	for (int to : G[v])
		if (to ^ fa){
			dfs(to, v);
			st[++m][0] = dfn[v];
		}
}
inline int query_st(int l, int r){
	int k = mlg[r - l + 1];
	return min(st[l][k], st[r - (1 << k) + 1][k]);
}
inline int query_lca(int u, int v){
	if (!u || !v) return u + v;
	return rdfn[query_st(min(pos[dfn[u]], pos[dfn[v]]), max(pos[dfn[u]], pos[dfn[v]]))];
}
inline int query_st2(int l, int r){
	int k = mlg[r - l + 1];
	return query_lca(st2[l][k], st2[r - (1 << k) + 1][k]);
}
void init(){
	for (int i = 1;i <= 1e6;++i)
		mlg[i] = mlg[i >> 1] + 1;
	dfs(1, 0);
	for (int i = 1;i <= 20;++i)
		for (int j = 1;j + (1 << i) <= m;++j)
			st[j][i] = min(st[j][i-1], st[j + (1 << (i - 1))][i-1]);
	for (int i = 1;i <= n;++i)
		st2[i][0] = i;
	for (int i = 1;i <= 20;++i)
		for (int j = 1;j + (1 << i) <= n;++j)
			st2[j][i] = query_lca(st2[j][i-1], st2[j + (1 << (i - 1))][i-1]);
	#if debug
/*		for (int i = 1;i <= m;++i)
			printf ("%d ", mlg[i]);
		puts("");
		for (int i = 1;i <= n;++i)
			printf ("%d ", dfn[i]);
		puts("");
		for (int i = 1;i <= n;++i)
			printf ("%d ", rdfn[i]);
		puts("");
		for (int i = 1;i <= n;++i)
			printf ("%d ", pos[i]);
		puts("");
		for (int i = 0;i <= mlg[m];++i){ 
			for (int j = 1;j <= m;++j)
				printf ("%d ", st[j][i]);
			puts("");
		}
		for (int i = 0;i <= mlg[n];++i){
			for (int j = 1;j <= n;++j)
				printf ("%d ", st2[j][i]);
			puts("");
		} 	*/
	#endif
}
inline int query_method1(int l, int r, int k){
	int ans = 0;
	for (int i = l, j = l + k - 1;j <= r;++i, ++j){
		ans = max(ans, dep[query_st2(i, j)]);
	}
	return ans;
}
int main(){
	#if debug
		freopen("query4.in", "r", stdin);
		freopen("query4.out", "w", stdout);
	#else
		freopen("query.in", "r", stdin);
		freopen("query.out", "w", stdout);
	#endif
	scanf ("%d", &n);
	for (int i = 1;i < n;++i){
		int u, v;
		scanf ("%d%d", &u, &v);
		G[u].push_back(v), G[v].push_back(u);
	}
	init();
	scanf ("%d", &q);
	while (q--){
		int l, r, k;
		scanf ("%d%d%d", &l, &r, &k);
		printf ("%d\n", query_method1(l, r, k));
	}
	return 0;
} 
