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

const int MAXN = 1e6 + 5;

int cnt;
int head[MAXN];

struct edge
{
	int to, nxt;
}e[MAXN << 1];

void Add(int u, int v)
{
	e[++cnt] = edge{v, head[u]};
	head[u] = cnt;
}

int tim;
int fa[MAXN], dep[MAXN], siz[MAXN], son[MAXN], top[MAXN];

void Dfs1(int u, int f)
{
	fa[u] = f, dep[u] = dep[f] + 1, siz[u] = 1;
	for (int i = head[u]; i; i = e[i].nxt)
	{
		int v = e[i].to;
		if (v == f)
			continue;
		Dfs1(v, u);
		siz[u] += siz[v];
		if (siz[v] > siz[son[u]])
			son[u] = v;
	}
}

void Dfs2(int u, int t)
{
	top[u] = t;
	if (!son[u])
		return;
	Dfs2(son[u], t);
	for (int i = head[u]; i; i = e[i].nxt)
	{
		int v = e[i].to;
		if (top[v])
			continue;
		Dfs2(v, v);
	}
}

int Lca(int u, int v)
{
	while (top[u] != top[v])
	{
		if (dep[top[u]] < dep[top[v]])
			swap(u, v);
		u = fa[top[u]];
	}
	return dep[u] < dep[v] ? u : v;
}

int main()
{
	freopen("query.in", "r", stdin); freopen("query.out", "w", stdout);
	int n;
	scanf("%d", &n);
	for (int i = 1; i < n; i++)
	{
		int u, v;
		scanf("%d%d", &u, &v);
		Add(u, v); Add(v, u);
	}
	Dfs1(1, 0); Dfs2(1, 1);
	int q;
	scanf("%d", &q);
	while (q--)
	{
		int l, r, k;
		scanf("%d%d%d", &l, &r, &k);
		int ans = 0;
		for (int i = l; i + k - 1 <= r; i++)
		{
			int pos = i;
			for (int j = i + 1; j <= i + k - 1; j++)
				pos = Lca(pos, j);
			ans = max(ans, dep[pos]);
		}
		printf("%d\n", ans);
	}
	return 0;
}
