#include <cmath>
#include <cstdio>
#include <iostream>
using namespace std;
const int N = 5e5 + 5;
int n, q;

int idx, h[N];
struct edge{int to, nxt;}e[N << 1];
void addEdge(int u, int v)
{
	e[++idx] = (edge){v, h[u]};
	h[u] = idx;
}

int cnt, st[N], ed[N], dep[N], eul[N << 1];
void DFS(int u, int f)
{
	eul[st[u] = ed[u] = ++cnt] = u, dep[u] = dep[f] + 1;
	for(int i = h[u];i;i = e[i].nxt)
	{
		int v = e[i].to;
		if(v == f)continue;
		DFS(v, u), eul[ed[u] = ++cnt] = u;
	}
}

int stMn[N][30], stMx[N][30], lca[N << 1][30];
void init(int n)
{
	for(int i = 1;i <= n;i++)lca[i][0] = dep[eul[i]];
	for(int j = 1;(1 << j) <= n;j++)
		for(int i = 1;i + (1 << j) - 1 <= n;i++)
			lca[i][j] = min(lca[i][j - 1], lca[i + (1 << j - 1)][j - 1]);
	n = (n + 1) >> 1;
	for(int i = 1;i <= n;i++)stMn[i][0] = st[i], stMx[i][0] = ed[i];
	for(int j = 1;(1 << j) <= n;j++)
		for(int i = 1;i + (1 << j) - 1 <= n;i++)
			stMn[i][j] = min(stMn[i][j - 1], stMn[i + (1 << j - 1)][j - 1]),
			stMx[i][j] = max(stMx[i][j - 1], stMx[i + (1 << j - 1)][j - 1]);
}
int queryLCA(int l, int r){int k = log2(r - l + 1);return min(lca[l][k], lca[r - (1 << k) + 1][k]);}
int querySt(int l, int r){int k = log2(r - l + 1);return min(stMn[l][k], stMn[r - (1 << k) + 1][k]);}
int queryEd(int l, int r){int k = log2(r - l + 1);return max(stMx[l][k], stMx[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), addEdge(u, v), addEdge(v, u);
	DFS(1, 0), init((n << 1) - 1);
	scanf("%d", &q);
	while(q--)
	{
		int l, r, k, res = 0;
		scanf("%d%d%d", &l, &r, &k);
		for(int i = l;i + k - 1 <= r;i++)res = max(res, queryLCA(querySt(i, i + k - 1), queryEd(i, i + k - 1)));
		printf("%d\n", res);
	}
	return 0;
}
