#include <bits/stdc++.h>
using namespace std;
const int MAXN = 5e5 + 5;
int tree[MAXN],f[MAXN][25],dep[MAXN];
struct edge
{
	int nxt,to;
}e[MAXN * 2];
int head[MAXN],tot;
inline void merge(int u,int v)
{
	e[++tot] = {head[u],v};
	head[u] = tot;
}
inline void init(int u,int fa)
{
	dep[u] = dep[fa] + 1;
	f[u][0] = fa;
	for (int i = 1; i <= 20; i++) f[u][i] = f[f[u][i - 1]][i - 1];
	for (int i = head[u],v; i; i = e[i].nxt)
	{
		v = e[i].to;
		if (v == fa) continue;
		init(v,u);
	}
}
inline int LCA(int x,int y)
{
	if (!x) return y;
	if (!y) return x;
	if (dep[x] > dep[y]) swap(x,y);
	for (int i = 20; i >= 0; i--)
	{
		if (dep[f[y][i]] >= dep[x]) y = f[y][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];
}
inline void build(int l,int r,int q)
{
	if (l == r)
	{
		tree[q] = l;
		return ;
	}
	int mid = (l + r) / 2;
	build(l,mid,q * 2),build(mid + 1,r,q * 2 + 1);
	tree[q] = LCA(tree[q * 2],tree[q * 2 + 1]);
}
inline int query(int l,int r,int q,int x,int y)
{
	if (x <= l && r <= y) return tree[q];
	int mid = (l + r) / 2,res = 0;
	if (x <= mid) res = query(l,mid,q * 2,x,y);
	if (y > mid) res = LCA(res,query(mid + 1,r,q * 2 + 1,x,y));
	return res;
}
int main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	freopen("query.in","r",stdin);
	freopen("query.out","w",stdout);
	int n,q,x,y,k,ans;
	cin >> n;
	for (int i = 1,u,v; i < n; i++)
	{
		cin >> u >> v;
		merge(u,v),merge(v,u);
	}
	init(1,0);
	build(1,n,1);
	cin >> q;
	while (q--)
	{
		cin >> x >> y >> k;
		ans = 0;
		for (int i = x,res; i <= y - k + 1; i++)
		{
			res = query(1,n,1,i,i + k - 1);
			ans = max(ans,dep[res]);
		}
		cout << ans << '\n';
	}
	return 0;
}
/*
6
5 6
6 1
6 2
2 3
2 4
3
2 5 2
1 4 1
1 6 3
*/
