//多测不清空，十年OI一场空 
#include<bits/stdc++.h>
#include<algorithm>
#include<queue>
#include<cstring>
#include<string>
#include<vector>
using namespace std;
const int maxn=500010;
int read();
int readc();
void workA();
void work(int g,int fa,int hh);
int n,du[maxn],pp,h[maxn];
vector<int> p[maxn];
int main()
{
	freopen("query.in","r",stdin);
	freopen("query.out","w",stdout);
	//printf("15");
	memset(du,0,sizeof(du));
	n=read();//printf("%d",n);
	p[1].push_back(0);
	for(int i=1;i<=n-1;i++)
	{
		int x,y;
		x=read(),y=read();//printf("%d %d\n",x,y);
		p[x].push_back(y);p[y].push_back(x);
	}
	//printf("15");
	work(1,0,1);
	int kkk=0;
	for(int i=1;i<=n;i++)
	{
		if(du[i]==1) kkk++;
	}
	//printf("%d",kkk);
	if(kkk==n-1) workA();
	return 0;
}
int read()
{
	int x=0,f=0;char ch=getchar();
	while(!isdigit(ch)){f|=ch=='-';ch=getchar();}
	while(isdigit(ch)){x=(x<<3)+(x<<1)+(ch^48);ch=getchar();}
	return x;
}
int readc()
{
	char ch=getchar();
	while((ch==' ')||(ch=='\n')||(ch=='\r')) ch=getchar();
	return ch;
}
void work(int g,int fa,int hh)
{
	h[g]=hh;//printf("%d\n",hh);
	int si=p[g].size();//printf("%d",si-1);
	for(int i=0;i<si;i++)
	{
		int u=p[g][i];
		if(u==fa) continue;
		du[g]++;//printf("%d\n",du[g]++);
		work(u,g,hh+1);
	}
	//return;
}
void workA()
{
	pp=read();int l,r,k;deque<int> q,qg;
	//printf("%d",pp);
	for(int i=1;i<=pp;i++)
	{
		q.clear();qg.clear();
		l=read();r=read();k=read();
		//printf("%d %d %d\n",l,r,k);
		int maxx=0;
		q.push_back(h[l]);qg.push_back(l);//printf("%d\n",h[l]);
		for(int j=l+1;j<l+k;j++) 
		{
			//printf("%d\n",j);
			while(!q.empty()&&q.back()>=h[j])
			{
				q.pop_back();
				qg.pop_back();
			}
			q.push_back(h[j]);
			//for(int i=0;i<q.size();i++) printf("%d",q[i]);
			qg.push_back(j);
		}
		maxx=max(maxx,q.front());
		for(int j=l+k;j<=r;j++)
		{
			if(!qg.empty()&&qg.front()==j-k)
			{
				q.pop_front();
				qg.pop_front();
			}
			while(!q.empty()&&q.back()>=h[j])
			{
				q.pop_back();
				qg.pop_back();
			}
			q.push_back(h[j]);
			qg.push_back(j);
			maxx=max(maxx,q.front());
		}
		//printf("vv");
		printf("%d\n",maxx);
	}
}
























