#include <bits/stdc++.h>
#define Code using
#define by namespace
#define zzx std
Code by zzx;
int n, q, dep[500010], l[500010], r[500010], k[500010];
vector<int> e[500010];
int l2[500010], fa[500010][21], qlca[500010][21];
void init()
{
	l2[1] = 0;
	for(int i = 2; i <= n; ++i)
	{
		l2[i] = l2[i / 2] + 1;
	}
}
void dfs(int l, int u)
{
	fa[u][0] = l;
	for(int i = 1; i <= 20; ++i)
	{
		fa[u][i] = fa[fa[u][i - 1]][i - 1];
	}
	for(int i = 0; i < e[u].size(); ++i)
	{
		int v = e[u][i];
		if(v == l)
		{
			continue;
		}
		dep[v] = dep[u] + 1;
		dfs(u, v);
	}
}
int LCA(int x, int y)
{
	if(dep[y] > dep[x])
	{
		swap(x, y);
	}
	for(int i = 20; i >= 0; --i)
	{
		if(dep[fa[x][i]] >= dep[y])
		{
			x = fa[x][i];
		}
	}
	if(x == y)
	{
		return x;
	}
	for(int i = 20; i >= 0; --i)
	{
		if(fa[x][i] != fa[y][i])
		{
			x = fa[x][i];
			y = fa[y][i];
		}
	}
	return fa[x][0];
}
int find_qlca(int x, int y)
{
	int l = l2[y - x + 1];
	int p = LCA(qlca[x][l], qlca[y - (1 << l) + 1][l]);
	return dep[p];
}
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);
	}
	scanf("%d", &q);
	int flag = 1;
	for(int i = 1; i <= q; ++i)
	{
		scanf("%d %d %d", &l[i], &r[i], &k[i]);
		if(k[i] != r[i] - l[i] + 1)
		{
			flag = 0;
		}
	}
	if((n <= 5000 && q <= 5000) || flag == 1)
	{
		init();
		dep[1] = 1;
		dfs(1, 1);
		for(int i = 1; i <= n; ++i)
		{
			qlca[i][0] = i;
		}
		for(int i = 1; i <= 20; ++i)
		{
			for(int j = 1; j <= (n - (1 << i) + 1); ++j)
			{
				int k = j + (1 << (i - 1));
				qlca[j][i] = LCA(qlca[j][i - 1], qlca[k][i - 1]);
			}
		}
		for(int i = 1; i <= q; ++i)
		{
			int ans = 0;
			for(int j = l[i]; j <= r[i] - k[i] + 1; ++j)
			{
				ans = max(ans, find_qlca(j, j + k[i] - 1));
			}
			printf("%d\n", ans);
		}
	}
	else
	{
		for(int i = 1; i <= q; ++i)
		{
			printf("0\n");
		}
	}
	fclose(stdin);
	fclose(stdout);
	return 0;
}
//10:39 finish 20pts
//11:00 finish 32pts
