#include<bits/stdc++.h>
using namespace std;
struct datay
{
	int l,r,v,ans,p;
}b[500005];
int n,fa[500005][21],f[2000005],deep[500005],m,f1[500005];
int d[5005][5005];
vector<int> a[500005];
void dijah(int x,int l,int r,int k,int v)
{
	if(l==r){f1[x]=max(f1[x],v);return;}
	int lc=(x<<1),rc=(x<<1)|1,mid=(l+r)>>1;
	if(k<=mid)dijah(lc,l,mid,k,v);
	if(k>mid)dijah(rc,mid+1,r,k,v);
	f1[x]=max(f1[lc],f1[rc]);
	return;
}
int gaia(int x,int l,int r,int ql,int qr)
{
	if(ql<=l&&r<=qr)return f1[x];
	int lc=(x<<1),rc=(x<<1)|1,mid=(l+r)>>1,h=0;
	if(ql<=mid)h=gaia(lc,l,mid,ql,qr);
	if(qr>mid)h=max(h,gaia(rc,mid+1,r,ql,qr));
	return h;
} 
bool cmp1(datay q,datay w){return q.v>w.v;}
bool cmp2(datay q,datay w){return q.p<w.p;}
void dfs1(int x,int y)
{
	fa[x][0]=y,deep[x]=deep[y]+1;
	for(int i=0;i<a[x].size();i++)
	{
		if(a[x][i]==y)continue;
		dfs1(a[x][i],x);
	}
	return;
}
int LCA(int x,int y)
{
	if(deep[x]<deep[y])swap(x,y);
	for(int i=20;i>=0;i--)x=(deep[fa[x][i]]>=deep[y])?fa[x][i]:x;
	if(x==y)return x;
	for(int i=20;i>=0;i--)x=(fa[x][i]!=fa[y][i])?fa[x][i]:x,y=(deep[x]!=deep[y])?fa[y][i]:y;
	return fa[x][0];
}
void build(int x,int l,int r)
{
	if(l==r){f[x]=l;return;}
	int lc=(x<<1),rc=(x<<1)|1,mid=(l+r)>>1;
	build(lc,l,mid),build(rc,mid+1,r),f[x]=LCA(f[lc],f[rc]);
	return;
}
int query(int x,int l,int r,int ql,int qr)
{
	if(ql<=l&&r<=qr)return f[x];
	int lc=(x<<1),rc=(x<<1)|1,mid=(l+r)>>1,h=ql;
	if(ql<=mid)h=query(lc,l,mid,ql,qr);
	if(qr>mid)h=LCA(h,query(rc,mid+1,r,ql,qr));
	return h;
}
int main()
{
	freopen("query.in","r",stdin);
	freopen("query.out","w",stdout);
	int x,y,z,s;
	scanf("%d",&n);
	for(int i=1;i<n;i++)
	{
		scanf("%d%d",&x,&y);
		a[x].push_back(y),a[y].push_back(x);
	}
	dfs1(1,0);
	for(int i=1;i<=20;i++)
		for(int j=1;j<=n;j++)fa[j][i]=fa[fa[j][i-1]][i-1];
	if(n<=5000)
	{
		scanf("%d",&m);
		for(int i=1;i<=m;i++)scanf("%d%d%d",&b[i].l,&b[i].r,&b[i].v),b[i].p=i;
		sort(b+1,b+m+1,cmp1);
		for(int i=1;i<=n;i++)
		{
			d[i][i]=i;
			for(int j=i+1;j<=n;j++)d[i][j]=LCA(d[i][j-1],j);
		}
//		for(int i=1;i<=n;i++)
//			for(int j=i;j<=n;j++)cout<<i<<' '<<j<<' '<<d[i][j]<<'\n';
		b[0].v=n+1;
		for(int i=1;i<=m;i++)
		{
			for(int j=b[i-1].v-1;j>=b[i].v;j--)
				for(int u=1;u<=n-j+1;u++)dijah(1,1,n,u+j-1,deep[d[u][u+j-1]]);
//			for(int j=1;j<=n;j++)cout<<gaia(1,1,n,j,j)<<' ';
//			cout<<'\n';
//			for(int j=1;j<=4*n;j++)cout<<f1[j]<<' ';
//			cout<<'\n';
			b[i].ans=gaia(1,1,n,b[i].l+b[i].v-1,b[i].r);
		}
		sort(b+1,b+m+1,cmp2);
		for(int i=1;i<=m;i++)printf("%d\n",b[i].ans);
		return 0;
	}
	build(1,1,n);
	scanf("%d",&m);
	for(int i=1;i<=m;i++)
	{
		scanf("%d%d%d",&x,&y,&z),s=0;
		if(n>5000)
		{
			for(int j=x;j<=y;j++)
				for(int u=j+z-1;u<=y;u++)s=max(s,deep[query(1,1,n,j,u)]);
			printf("%d\n",s);
		}
	}







  return 0;
}

