#include <iostream>
#include <vector>
#include <cstdio>

using namespace std;

const int N = 500010;

int dep[N],f[N][20],b[N];
vector<int>G[N];

void DFS(int u,int fa)
{
	f[u][0] = fa;
	dep[u] = dep[fa] + 1;
	int i;
	for(i = 1;(1<<i) <= dep[u];i++) f[u][i] = f[f[u][i - 1]][i - 1];
	for(i = 0;i < G[u].size();i++)
	{
		int v = G[u][i];
		if(v == fa) continue;
		DFS(v,u);
	}
}

int LCA(int x,int y)
{
	if(dep[x] < dep[y]) swap(x,y);
	int d = dep[x] - dep[y],i;
	for(i = 0;i <= 19;i++) if((1<<i)&d) x = f[x][i];
	if(x == y) return x;
	for(i = 19;i >= 0;i--)
	{
		if(f[x][i] != f[y][i])
		{
			x = f[x][i];
			y = f[y][i];
		}
	}
	return f[x][0];
}

int Solve(int x,int y)
{
	int i;
	for(i = 0;i <= y - x;i++) b[i] = x + i;
//	sort(b + 1,b + y - x,cmp);
	int lca = b[0];
	for(i = 1;i <= y - x;i++) lca = LCA(lca,b[i]);
	return lca;
}

int main()
{
	freopen("query.in","r",stdin);
	freopen("query.out","w",stdout);
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int n,i,q;
	cin>>n;
	for(i = 1;i < n;i++)
	{
		int u,v;
		cin>>u>>v;
		G[u].push_back(v);
		G[v].push_back(u);
	}
	DFS(1,0);
	cin>>q;
	while(q--)
	{
		int l,r,k,ans = 0;
		cin>>l>>r>>k;
		int len = k;
		for(i = l;i + len - 1 <= r;i++) ans = max(ans,dep[Solve(i,i + len - 1)]);
		cout<<ans<<endl;
	}
	return 0;
}
