#include<bits/stdc++.h>
#define max(aa,bb) (aa>bb?aa:bb)
#define min(aa,bb) (aa<bb?aa:bb)
#define inf 1e7
using namespace std;
int n,m,k,z,x,s,y,tz,len,dis[5005][5005],ans,sum,smax,smin;
int minn[5005][5005],maxn[5005][5005];
int dfn[500005],dep[500005],fa[500005][19];
int em,e[5000005],nx[5000005],lt[500005];
int tr[2][10000005],bz[500005];
bool ap;
void in(int xx,int yy){
	e[++em]=yy,nx[em]=lt[xx],lt[xx]=em;
	return ;
}
long long read(){
	char ch=getchar();
	long long ip=1,xx=0;
	while((ch<'0'||ch>'9')&&ch!='-') ch=getchar();
	if(ch=='-'){
		ip=-1,ch=getchar();
		while(ch<'0'||ch>'9') ch=getchar();
	}
	while(ch>='0'&&ch<='9')
		xx=xx*10+ch-'0',ch=getchar();
	return xx*ip;
}
void dfs(int xx){
	dfn[xx]=(++len);
	for(int i=lt[xx];i!=0;i=nx[i]){
		if(dfn[e[i]]!=0) continue;
		dep[len+1]=dep[dfn[xx]]+1,fa[len+1][0]=dfn[xx];
		for(int j=1;j<19;j++) fa[len+1][j]=fa[fa[len+1][j-1]][j-1];
		dfs(e[i]);
	}
	return ;
}
void sou(int xx,int fa,int rt){
	dis[dfn[rt]][dfn[xx]]=dis[dfn[rt]][dfn[fa]]+1;
	for(int i=lt[xx];i!=0;i=nx[i]){
		if(e[i]==fa) continue;
		sou(e[i],xx,rt);
	}
	return ;
}
void res(int ss,int l,int r){
	if(l>r) return ;
	if(l==r){
		tr[0][ss]=dfn[l];
		tr[1][ss]=dfn[l];
		return ;
	}
	int mid=(l+r)/2;
	res(ss*2,l,mid),res(ss*2+1,mid+1,r);
	tr[0][ss]=min(tr[0][ss*2],tr[0][ss*2+1]);
	tr[1][ss]=max(tr[1][ss*2],tr[1][ss*2+1]);
	return ;
}
int find_max(int ss,int l,int r,int lp,int rp){
	if(l>r||l>rp||r<lp) return -inf;
	if(l>=lp&&r<=rp) return tr[1][ss];
	int mid=(l+r)/2;
	int o=find_max(ss*2,l,mid,lp,rp);
	int p=find_max(ss*2+1,mid+1,r,lp,rp);
	return max(o,p);
}
int find_min(int ss,int l,int r,int lp,int rp){
	if(l>r||l>rp||r<lp) return inf;
	if(l>=lp&&r<=rp) return tr[0][ss];
	int mid=(l+r)/2;
	int o=find_min(ss*2,l,mid,lp,rp);
	int p=find_min(ss*2+1,mid+1,r,lp,rp);
	return min(o,p);
}
int lca(int xx,int yy){
	int tx=xx,ty=yy;
	if(dep[tx]<dep[ty]) swap(tx,ty);
	for(int i=18;i>=0;i--)
		if(dep[fa[tx][i]]>=dep[ty]) tx=fa[tx][i];
	if(tx==ty) return tx;
	for(int i=18;i>=0;i--)
		if(fa[tx][i]!=fa[ty][i]) tx=fa[tx][i],ty=fa[ty][i];
	return fa[tx][0];
}
int main(){
	//query
	freopen("query.in","r",stdin);
	freopen("query.out","w",stdout);
	n=read();
	for(int i=1;i<n;i++){
		x=read(),y=read();
		in(x,y),in(y,x);
		bz[x]++,bz[y]++;
	}
	ap=1;
	for(int i=1;i<=n;i++){
		if(bz[i]>2) ap=0; 
	}
	tz=read();
	dep[1]=1;
	dfs(1);
	if(n<=5000){
		for(int i=1;i<=n;i++)
			sou(i,0,i);
		for(int i=1;i<=n;i++){
			minn[i][i]=dfn[i],maxn[i][i]=dfn[i];
			for(int j=i+1;j<=n;j++){
				minn[i][j]=min(dfn[j],minn[i][j-1]);
				maxn[i][j]=max(dfn[j],maxn[i][j-1]);
			}
		}
		while(tz--){
			ans=0;
			x=read(),y=read(),k=read();
			for(int i=x;i<=y-k+1;i++){
				sum=dep[minn[i][i+k-1]]+dep[maxn[i][i+k-1]]-dis[minn[i][i+k-1]][maxn[i][i+k-1]];
				ans=max(ans,sum/2);
			}
			printf("%d\n",ans+1);
		}
		return 0;
	}
	res(1,1,n);
	while(tz--){
		ans=0;
		x=read(),y=read(),k=read();
		for(int i=x;i<=y-k+1;i++){
			smax=find_max(1,1,n,i,i+k-1);
			smin=find_min(1,1,n,i,i+k-1);
			sum=lca(smax,smin);
			ans=max(ans,dep[sum]);
		}
		printf("%d\n",ans);
	}
	return 0;
}
