#include<iostream>
#include<cstdio>
#include<vector>
using namespace std;
vector<int > v[500010];
int n,ans,deep[500010],q;
void qwq(int k,int fa)
{
	for(int i=0;i<v[k].size();i++)
	  if(v[k][i]!=fa)
	    {
	    	deep[v[k][i]]=deep[k]+1;
			qwq(v[k][i],k);
	    }
}
int qu(int l,int r,int k)
{
	int sum=-114514;
	for(int i=l;i<=r-k+1;i++)
	{
		int kk=114514;
		for(int j=i;j<=i+k-1;j++)
		  kk=min(kk,deep[j]);
		sum=max(sum,kk);
	}
	return sum;
}
int main()
{
	ios::sync_with_stdio(0);
	freopen("query.in","r",stdin);
	freopen("query.out","w",stdout);
	cin>>n;
	for(int i=1;i<n;i++)
	{
		int a,b;
		cin>>a>>b;
		v[a].push_back(b);
		v[b].push_back(a);
	}
	deep[1]=1;
	qwq(1,0);
	cin>>q;
	for(int i=1;i<=q;i++)
	{
		int l,r,k;
		cin>>l>>r>>k;
		cout<<qu(l,r,k)<<"\n";
	}
}
