#include<bits/stdc++.h>
using namespace std;
struct node
{
	int father,depth;
	vector<int> son;
}a[500001];
vector<int> mapp[500001];
int n,q,bz[500001][3];
void buildtree(int root,int father,int depth)
{
	a[root].depth=depth;
	a[root].father=father;
	int i;
	for(i=0;i<mapp[root].size();i++)
	{
		if(mapp[root][i]==father) continue;
		a[root].son.push_back(mapp[root][i]);
		buildtree(mapp[root][i],root,depth+1);
	}
}
int findlca(int x,int y)
{
	if(a[x].depth>a[y].depth) swap(x,y);
	while(a[y].depth>a[x].depth)
	{
		y=a[y].father;
	}
	while(x!=y)
	{
		x=a[x].father;
		y=a[y].father;
	}
	return x;
}
int main()
{
	freopen("query.in","r",stdin);
	freopen("query.out","w",stdout);
	cin >> n;
	int i,j,k,x,y,u;
	for(i=1;i<=n-1;i++)
	{
		scanf("%d%d",&x,&y);
		mapp[x].push_back(y);
		mapp[y].push_back(x);
	}
	buildtree(1,0,1);
	cin >> q;
	for(u=1;u<=q;u++)
	{
		scanf("%d%d%d",&x,&y,&k);
		int maxdepth=0;
		for(i=x;i<=y-k+1;i++)
		{
			int lca=i;
			for(j=i+1;j<=i+k-1;j++)
			{
				lca=findlca(lca,j);
			}
			maxdepth=max(maxdepth,a[lca].depth);
		}
		printf("%d\n",maxdepth);
	}
	return 0;
}
