#include <bits/stdc++.h>

using namespace std;
const int N = 5e5+3;

int n, q, dep[N], fa[21][N], f[21][N], lg[N];
struct node {
	int v, n;
} e[N<<1];
int h[N], tot;
inline int rd() {
	int x=0, f=1;
	char c=getchar();
	while(c<'0' || c>'9') {
		if(c == '-') f=-1;
		c=getchar();
	}
	while(c>='0' && c<='9') {
		x = (x<<3)+(x<<1)+(c^48);
		c=getchar();
	}
	return x*f;
}
namespace sgt {
	int t[N<<2];
	void build(int p, int l, int r) {
		
	}
}

void add(int u, int v) {
	e[++tot] = {v, h[u]}, h[u] = tot;
}
void dfs(int u, int p) {
//	printf("%d %d\n", u, p);
	dep[u] = dep[p]+1;
	fa[0][u] = p;
	for(int k=1; 1<<k <= dep[u]; ++k) fa[k][u] = fa[k-1][fa[k-1][u]];
	for(int i=h[u]; i; i=e[i].n) {
		int v = e[i].v;
		if(v == p) continue;
		dfs(v, u);
	}
}
inline int lca(int x, int y) {
//	printf("%d %d\n", x, y);
	if(dep[x] < dep[y]) swap(x, y);
	for(int k = lg[dep[x]]; ~k; --k) if(dep[fa[k][x]] >= dep[y]) x = fa[k][x];
	if(x == y) return x;
	for(int k = lg[dep[x]]; ~k; --k) {
		if(fa[k][x] != fa[k][y]) x = fa[k][x], y = fa[k][y];
	}
	return fa[0][x];
}
//int getlca(int x, int y) {
//	printf("%d %d %d\n", x, y, lca(x, y));
//	return lca(x, y);
//}
inline int ask(int l, int r) {
	int k = lg[r-l+1];
	return lca(f[k][l], f[k][r-(1<<k)+1]);
}
int main() {
	freopen("query.in", "r", stdin);
	freopen("query.out", "w", stdout);
	n=rd();
	for(int i=1; i < n; ++i) {
		int u, v;
		u=rd(), v=rd();
		add(u, v), add(v, u);
	}
	lg[0] = -1;
	for(int i=1; i <= n; ++i) lg[i] = lg[i>>1]+1;
	dfs(1, 0);
	for(int i=1; i <= n; ++i) f[0][i] = i;
	for(int i=1; i <= lg[n]; ++i) {
		for(int j=1; j+(1<<i)-1 <= n; ++j) {
			f[i][j] = lca(f[i-1][j], f[i-1][j+(1<<i-1)]);
//			printf("%d %d %d\n", i, j, f[i][j]);
		}
	}
	q=rd();

	while(q--) {
		int l, r, k, ans=0;
		l=rd(), r=rd(), k=rd();
		for(int i=l; i+k-1 <= r; ++i) {
			int j = i+k-1;
//			cout << ask(i, j) << endl;
			ans = max(ans, dep[ask(i, j)]);
		}
		printf("%d\n", ans);
	}
	return 0;
}

