#include <bits/stdc++.h>
#define rep1(i,a,b) for (int i = (a);i <= (b);i++)
#define rep2(i,a,b) for (int i = (a);i >= (b);i--)
using namespace std;
const int N = 5e5 + 10;
const int INF = 5e5;
int n,u,v,q,l,r,k,ans;
int fa[N][30],dep[N],lca[N][30],lg[N];
vector<int> graph[N];
void dfs1(int p,int faa)
{
	dep[p] = dep[faa] + 1;
	fa[p][0] = faa;
	rep1(i,1,25)
		fa[p][i] = fa[fa[p][i - 1]][i - 1];
	for (auto j : graph[p])
		if (j != faa)
			dfs1(j,p);
}
int lcaa(int u,int v)
{
	if (dep[u] < dep[v])
		swap(u,v);
	rep2(i,25,0)
		if (dep[fa[u][i]] >= dep[v])
			u = fa[u][i];
	if (u == v)
		return u;
	rep2(i,25,0)
		if (fa[u][i] != fa[v][i])
		{
			u = fa[u][i];
			v = fa[v][i];
		}
	return fa[u][0];
}
int query(int l,int r)
{
	int k = lg[r - l + 1];
	//return lcaa(lca[l][k],lca[r - (1 << k) + 1][k]);
	int ans = l;
	rep1(i,l + 1,r)
		ans = lcaa(ans,i);
	return ans;
}
int main()
{
 	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	freopen("query.in","r",stdin);
	freopen("query.out","w",stdout);
	cin >> n;
	rep1(i,2,INF)
		lg[i] = lg[i << 1] + 1;
	rep1(i,1,n - 1)
	{
		cin >> u >> v;
		graph[u].push_back(v);
		graph[v].push_back(u);
	}
	dfs1(1,0);
	rep1(i,1,n)
		lca[i][0] = i;
	rep1(j,1,25)
		for (int i = 1;i + (1 << j) - 1 <= n;i++)
			lca[i][j] = lcaa(lca[i][j - 1],lca[i + (1 << (j - 1))][j - 1]);
	cin >> q;
	while (q--)
	{
		cin >> l >> r >> k;
		ans = 0;
		for (int beg = l,end = l + k - 1;end <= r;beg++,end++)
			ans = max(ans,dep[query(beg,end)]);
		cout << ans << '\n';
	}
}

