#include <bits/stdc++.h>
using namespace std;
int n, m, k, l, r, q, dep[500005], f[500005][21], lg[500005];
int h[500005][21];
vector<int> g[500005];
void dfs(int x, int fa)
{
	dep[x] = dep[fa] + 1;
	for(int i = 0; i < g[x].size(); i++)
	{
		int y = g[x][i];
		if(y != fa) dfs(y, x);
	}
}
void d(int x, int fa)
{
	f[x][0] = fa;
	for(int i = 1; i <= lg[dep[x]]; i++)
		f[x][i] = f[f[fa][i - 1]][i - 1];
	for(int i = 0; i < g[x].size(); i++)
	{
		int y = g[x][i];
		if(y != fa) d(y, x);
	}
}
void pre()
{
	lg[1] = 0;
	for(int i = 2; i <= 500000; i++)
		lg[i] = lg[i >> 1] + 1;
}
int lca(int x, int y)
{
	if(dep[x] < dep[y]) swap(x, y);
	for(int i = 20; i >= 0; i--)
		if(dep[f[x][i]] >= dep[y]) x = f[x][i];
	if(x == y) return x;
	for(int i = 20; i >= 0; i--)
	{
		if(f[x][i] != f[y][i])
		{
			x = f[x][i];
			y = f[y][i];
		}
	}
	return f[x][0];
}
int LCA(int x, int y)
{
	int z = x;
	for(int i = x + 1; i <= y; i++)
		z = lca(z, i);
	return z;
}
int find(int x, int y)
{
	int len = lg[y - x + 1];
	return min(f[x][len], f[y - (1 << len)][len]);
}
signed main()
{
	freopen("query.in", "r", stdin);
	freopen("query.out", "w", stdout);
	pre();
	scanf("%d", &n);
	for(int i = 1; i < n; i++)
	{
		int x, y;
		scanf("%d%d", &x, &y);
		g[x].push_back(y);
		g[y].push_back(x);
	}
	dfs(1, 0);
	d(1, 0);
	for(int i = 1; i <= n; i++)
		h[i][0] = dep[i];
	for(int i = 1; i <= n; i++)
	{
		for(int j = 1; i + (1 << j) - 1 <= n; j++)
		{
			h[i][j] = min(h[i][j - 1], h[i + (1 << j - 1)][j - 1]);
		}
	}
	scanf("%d", &q);
	if(n >= 100000)
	{
		for(int i = 1; i <= q; i++)
		{
			scanf("%d%d%d", &l, &r, &k);
			int ans = 0;
			for(int j = l; j + k - 1 <= r; j++)
			{
				ans = max(ans, find(j, j + k - 1));
			}
			cout << ans << endl;
		}
		return 0;
	}
	for(int i = 1; i <= q; i++)
	{
		scanf("%d%d%d", &l, &r, &k);
		int ans = 0;
		for(int j = l; j + k - 1 <= r; j++)
			ans = max(ans, dep[LCA(j, j + k - 1)]);
		printf("%d\n", ans);
	}
	return 0;
}

