#include<cstdio>
using namespace std;
namespace IO
{
	const int lim=1000000;
	int curin,topin,topout;
	char in[lim+100],out[lim+100];
	char get()
	{
		if(curin==topin)
		{
			curin=0;
			topin=fread(in,1,lim,stdin);
		}
		if(topin==0)
		return 0;
		return in[curin++];
	}
	void read(int &x,int l=100)
	{
		int len=1;
		char c=get();
		while(c<'0'||c>'9')
		c=get();
		x=c-'0';
		while(len<l)
		{
			c=get();
			if(c<'0'||c>'9')
			return;
			x=x*10+c-'0';
		}
	}
	void flush()
	{
		fwrite(out,1,topout,stdout);
		topout=0;
	}
	class _{public:~_(){flush();}}__;
	void put(char c)
	{
		if(topout==lim)
		flush();
		out[topout++]=c;
	}
	void print(int x)
	{
		if(x<10)
		put(x+'0');
		else
		{
			print(x/10);
			put(x%10+'0');
		}
	}
}
using IO::put;
using IO::read;
using IO::print;
int n,q,i,j,u[600000],v[600000],deep[600000],fa[600000],num[600000],*mp[600000],ff[20][600000],lca[5050][5050],up[5050][5050],l,r,k,ans;
void dfs(long long x,long long d)
{
	long long i;
	deep[x]=d;
	for(i=1;i<=mp[x][0];i++)
	if(mp[x][i]!=fa[x])
	{
		fa[mp[x][i]]=x;
		dfs(mp[x][i],d+1);
	}
}
void dfs2(long long x)
{
	long long i;
	for(i=1;i<deep[x];i++)
	up[x][i]=up[fa[x]][i];
	for(i=deep[x];i<=n;i++)
	up[x][i]=x;
	for(i=1;i<=mp[x][0];i++)
	if(mp[x][i]!=fa[x])
	dfs2(mp[x][i]);
}
int main()
{
	freopen("query.in","r",stdin);
	freopen("query.out","w",stdout);
	read(n);
	for(i=1;i<n;i++)
	{
		read(u[i]);
		read(v[i]);
		num[u[i]]++;
		num[v[i]]++;
	}
	for(i=1;i<=n;i++)
	{
		mp[i]=new int[num[i]+1];
		mp[i][0]=0;
	}
	for(i=1;i<n;i++)
	{
		mp[u[i]][0]++;
		mp[u[i]][mp[u[i]][0]]=v[i];
		mp[v[i]][0]++;
		mp[v[i]][mp[v[i]][0]]=u[i];
	}
	dfs(1,1);
	dfs2(1);
	for(i=1;i<=n;i++)
	{
		lca[i][i]=i;
		for(j=i+1;j<=n;j++)
		{
			lca[i][j]=lca[i][j-1];
			while(up[j][deep[lca[i][j]]]!=lca[i][j])
			lca[i][j]=fa[lca[i][j]];
		}
	}
	read(q);
	for(i=1;i<=q;i++)
	{
		read(l);
		read(r);
		read(k);
		ans=0;
		for(j=l;j<=r-k+1;j++)
		if(deep[lca[j][j+k-1]]>ans)
		ans=deep[lca[j][j+k-1]];
		print(ans);
		put('\n');
	}
	return 0;
}
