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

const int N = 5010;
vector<int> G[N];
int dep[N] ,fa[N];

void dfs(int u ,int pre)
{
	dep[u] = dep[pre] + 1;
	fa[u] = pre;
	for (auto v : G[u])
		if (v != pre)
			dfs(v ,u);
}

int lca(int x ,int y)
{
	if (dep[x] < dep[y])
		swap(x ,y);
	while (dep[x] > dep[y])
		x = fa[x];
	
	if (x == y)
		return x;
	
	while (fa[x] != fa[y])
		x = fa[x] ,y = fa[y];
	
	return fa[x];
}

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);
		
		G[u].push_back(v);
		G[v].push_back(u); 
	}
	
	dfs(1 ,0);
	
	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 <= r - k + 1;i++)
		{
			int l = i;
			for (int j = i;j <= i + k - 1;j++)
				l = lca(l ,j);
			ans = max(ans ,dep[l]);
		}
		
		printf("%d\n",ans);
	}
	
	return 0;
}
