/*
 * A man need a dream
 * I want my dream come true
 * But It's so hard
 * So wait a moment or die for it
 * 
 * -- by larsr
 *  
 * NOIP is an important contest
 * I am afraid of it becouse maybe I will die for it
 * But stories don't have the end
 * Wair for me
 */
#include<cstdio>
#include<algorithm>
#include<vector>
#include<cstring>
#define N 500010
#define ll long long
using namespace std;
int n, q, fa[N][22], d[N];
int g[N], ql[N], qr[N], qk[N];
ll ans[N], sum[N];
vector<int>e[N];
void dfs(int now, int f)
{
	fa[now][0] = f;
	for(int i = 1; i <= 20; i++)fa[now][i] = fa[fa[now][i - 1]][i - 1];
	for(int to : e[now])
	if(to != f)
	{
		d[to] = d[now] + 1;
		dfs(to, now);
	}
}
int lca(int u, int v)
{
	if(d[u] < d[v])swap(u, v);
	for(int i = 20; i >= 0; i--)
		if(d[fa[u][i]] >= d[v])
			u = fa[u][i];
	if(u == v)return u;
	for(int i = 20; i >= 0; i--)
		if(fa[u][i] != fa[v][i])
			u = fa[u][i], v = fa[v][i];
	return fa[u][0];
}
int main()
{
	freopen("query.in", "r", stdin);
	freopen("query.out", "w", stdout);
	scanf("%d", &n);
	for(int i = 1; i < n; i++)
	{
		int u, v;
		scanf("%d%d", &u, &v);
		e[u].push_back(v);
		e[v].push_back(u);
	}
	d[1] = 1;
	dfs(1, 0);
	for(int i = 1; i < n; i++)g[i] = d[lca(i, i + 1)];
	scanf("%d", &q);
	for(int i = 1; i <= q; i++)
		scanf("%d%d%d", ql + i, qr + i, qk + i);
	for(int i = 1; i <= n; i++)
	{
		int minn = d[i];
		for(int j = i; j <= n; j++)
		{
			if(j != i)minn = min(minn, g[j - 1]);
			sum[j] = minn;
		}
		for(int j = 1; j <= q; j++)
		if(i + qk[j] - 1 <= qr[j] && i >= ql[j])
		ans[j] = max(ans[j], sum[i + qk[j] - 1]);
	}
	for(int i = 1; i <= q; i++)printf("%lld\n", ans[i]);
	return 0;
}
