#include<bits/stdc++.h>
#define LL long long
#define ls id<<1
#define rs id<<1|1 
using namespace std;
const int N=1e6+10;
const int INF=0x3f3f3f3f;
const LL p=1e9+7 ;
int read()
{
	char ch=getchar();
	int f=1,num=0;
	while(ch<'0'||ch>'9')
	{
		if(ch=='-')
			f=-1;
		ch=getchar();
	}
	while(ch>='0'&&ch<='9')
	{
		num=(num<<1)+(num<<3)+ch-'0';
		ch=getchar();
	}
	return f*num;
}
int n;
int head[N],ne[N],to[N],id,d[N];
void add(int x,int y)
{
	to[++id]=y,ne[id]=head[x],head[x]=id;
	to[++id]=x,ne[id]=head[y],head[y]=id;
}
int fa[N][21],dep[N];
void dfs(int u,int f)
{
	dep[u]=dep[f]+1;
	for(int i = 1;i<=20;i++)
		fa[u][i]=fa[fa[u][i-1]][i-1];
	for(int i = head[u];i;i=ne[i])
	{
		int v=to[i];
		if(v==f)
			continue;
		fa[v][0]=u;
		dfs(v,u);
	} 
}
int tup(int u,int k)
{
	int res=u;
	for(int i = 0,j=1;i<=20;i++,j<<=1)
		if(k&j)
			res=fa[res][i];
	return res;
}
int lca(int u,int v)
{
	if(dep[u]<dep[v])
		swap(u,v);
	u=tup(u,dep[u]-dep[v]);
	if(u==v)
		return u;
	for(int i = 20;i>=0;i--)
		if(fa[u][i]!=fa[v][i])
			u=fa[u][i],v=fa[v][i];
	return fa[u][0];
}
int res[5005][5005];
int tl[N*2];
void pushup(int id)
{
	tl[id]=lca(tl[ls],tl[rs]);
}
void build(int id,int l,int r)
{
	if(l==r)
	{
		tl[id]=l;
		return;
	}
	int mid=l+r>>1;
	build(ls,l,mid),build(rs,mid+1,r);
	pushup(id); 
}
int ql(int id,int l,int r,int L,int R)
{
	if(L<=l&&r<=R)
		return tl[id];
	int mid=l+r>>1;
	int res=0;
	if(L<=mid)
		res=ql(ls,l,mid,L,R);
	if(R>mid)
	{
		if(res)
			res=lca(res,ql(rs,mid+1,r,L,R));
		else res=ql(rs,mid+1,r,L,R);
	}
	return res;
}
int main()
{
	freopen("query.in","r",stdin);
	freopen("query.out","w",stdout);
	n=read();
	for(int i = 1,u,v;i<n;i++)
	{
		u=read(),v=read();
		add(u,v);
		d[u]++,d[v]++;
	}
//	puts("1");
	dfs(1,0);
	build(1,1,n);
	if(n<=5000)
	{
		for(int i = 1;i<=n;i++)
		{
			res[i][i]=i;
			for(int j = i+1;j<=n;j++)
				res[i][j]=lca(res[i][j-1],j);
		}
		int q=read();
		while(q--)
		{
			int l=read(),r=read(),k=read();
			int ans=1;
			for(int i = l;i+k-1<=r;i++)
				ans=max(ans,dep[res[i][i+k-1]]);
			printf("%d\n",ans);
		}
		return 0;
	}
	int q=read();
	while(q--)
	{
		int l=read(),r=read(),k=read();
		int ans=1;
		for(int i = l;i+k-1<=r;i++)
			ans=max(ans,dep[ql(1,1,n,i,i+k-1)]);
		printf("%d\n",ans);
	}
}
