#include <bits/stdc++.h>
#define ll long long
using namespace std;
const int _ = 5e5 + 5;



inline ll read()
{
	char c = getchar();
	ll f = 0,w = 1;
	while(c < '0' or c > '9'){if(c == '-') w = -1;c = getchar();}
	while(c >= '0' and c <= '9'){f = f * 10 + c - '0';c = getchar();}
	return w * f;
}

int n;
int dep[_],top[_],f[_],hson[_],siz[_];
vector <int> G[_];

void dfs1(int u,int fa)
{
	dep[u] = dep[fa] + 1;
	f[u] = fa;
	siz[u] = 1;
	for(int v : G[u])
	{
		if(v == fa) continue;
		
			dfs1(v,u);
		if(siz[v] > siz[hson[u]])
			hson[u] = v;
		siz[u] += siz[v];
	}
}

void dfs2(int u,int topx)
{
//	cout << u << endl;
	top[u] = topx;
	if(hson[u] == 0) return;
	dfs2(hson[u],topx);
	for(int v : G[u])
	{
		if(v == f[u] or v == hson[u]) continue;
		dfs2(v,v);
//		cout << u << " " << v << endl;
	}
}

int lca(int u,int v)
{
	while(top[u] != top[v])
	{
		if(dep[top[u]] > dep[top[v]])
			swap(u,v);
		v = f[top[v]]; 
		//u¸ßÔÚÉÏ 
	}
	return dep[u] > dep[v] ? v : u;
}

int main()
{
	freopen("query.in","r",stdin);
	freopen("query.out","w",stdout);
	n = read();
	for(int i = 1;i < n;i++)
	{
		int u = read();
		int v = read();
		G[u].push_back(v);
		G[v].push_back(u);
	}
	dfs1(1,0);
	dfs2(1,1);
	int q = read();
	while(q--)
	{
		int l,r,k;
		l = read();
		r = read();
		k = read();
		int ans = 0;
		for(int i = l;i <= r - k + 1;i++)
		{
			int op = i;
			for(int j = i + 1;j <= i + k - 1;j++)
			{
				op = lca(op,j);
			}
			ans = max(ans,dep[op]);
		}
		cout << ans << endl;
	}
	return 0;
}
