#include<bits/stdc++.h>
#define int long long
using namespace std;
const int N=5e5+5;
int fa[N],siz[N],son[N],top[N],n,q,u,v,L,R,l,r,Q[N],ans,cnt,d[N],dep[N],k,t;
int read()
{
	int w=0,f=1;char c=getchar();
	while(c<'0'||c>'9'){if(c=='-') f=-1;c=getchar();}
	while(c>='0'&&c<='9') w=(w<<3)+(w<<1)+c-'0',c=getchar();
	return w*f;
}
int tot,ver[2*N],ne[2*N],head[N];
void add(int u,int v)
{
	ver[++tot]=v;
	ne[tot]=head[u];
	head[u]=tot;
}
void dfs1(int x,int fath)
{
	fa[x]=fath;dep[x]=dep[fath]+1;siz[x]=1;
	int s=0;
	for(int i=head[x];i;i=ne[i])
	{
		int y=ver[i];
		if(y==fath) continue;
		dfs1(y,x);
		siz[x]+=siz[y];
		if(siz[y]>s) s=siz[y],son[x]=y;
	}
}
void dfs2(int x,int rt)
{
	top[x]=rt;
	if(son[x]) dfs2(son[x],rt);
	for(int i=head[x];i;i=ne[i])
	{
		int y=ver[i];
		if(y!=fa[x]&&y!=son[x]) dfs2(y,y);
	}
}
int lca(int x,int y)
{
	while(top[x]!=top[y])
	{
		if(dep[top[x]]>=dep[top[y]]) x=fa[top[x]];
		else y=fa[top[y]];
	}
	if(dep[x]>=dep[y]) return y;
	return x;
}
signed main()
{
	freopen("query.in","r",stdin);
	freopen("query.out","w",stdout);
	n=read();cnt=n;
	for(int i=1;i<n;i++)
	{
		u=read();v=read();
		add(u,v);add(v,u);
		d[u]++;d[v]++;
		if(d[u]==2) cnt--;
		if(d[v]==2) cnt--;
	}
	dfs1(1,0);
	dfs2(1,1);
	if(cnt==2)
	{
		q=read();
		while(q--)
		{
			L=read();R=read();k=read();
			l=1;r=0;ans=0;
			for(int i=L;i<=R;i++)
			{
				while(l<=r&&Q[l]<i-k+1) l++;
				while(l<=r&&dep[Q[r]]>=dep[i]) r--;
				Q[++r]=i;
				if(i-k+1>=L) ans=max(ans,dep[Q[l]]);
			}
			printf("%lld\n",ans);
		}
		return 0;
	}
	if(cnt==n-1)
	{
		q=read();
		while(q--)
		{
			l=read();r=read();k=read();
			if(k==1&&r>1) printf("2\n");
			else printf("1\n");
		}
		return 0;
	}
	q=read();
	while(q--)
	{
		l=read();r=read();k=read();ans=0;
		for(int i=l;i+k-1<=r;i++)
		{
			t=i;
			for(int j=i+1;j<=i+k-1;j++) t=lca(t,j);
			ans=max(ans,dep[t]);
		}
		printf("%lld\n",ans);
	}
}
