#include<bits/stdc++.h>
using namespace std;
struct T{
	int r,l,sum;
}t[100005];
int n,q,l1,r1,k,ans;
int e[500005],h[500005],ne[500005],cnt,v[500005];
struct L{
	int cs,sum;
}fa[100005];
void dfs(int xb,int sd){
	v[xb]=1;
	for(int i=h[xb];i!=-1;i=ne[i]){
		if(!v[e[i]]){
			dfs(e[i],sd+1);
			fa[e[i]].sum=xb;
			fa[e[i]].cs=sd;
		}
	}
	return ;
}

int LCa(int a,int b){
	int z=INT_MIN;
	for(int i=a;i!=-1;i=fa[i].sum){
		for(int j=b;j!=-1;j=fa[j].sum){
			if(i==j){
				z=max(z,max(fa[i].cs+1,fa[j].cs+1));
			}
		}
	}
	return z;
}


void build(int left,int right,int xb){
	if(left+1==right){
		t[xb].l=left;
		t[xb].r=right;
		t[xb].sum=LCa(left,right);
		return ;
	}
	build(left,(left+right)/2,xb*2);
	build((left+right)/2,right,xb*2+1);
	t[xb].l=left;
	t[xb].r=right;
	t[xb].sum=min(t[xb*2].sum,t[xb*2+1].sum);
	return ;
}


int find_(int xb,int ll,int rr){
	if(ll==rr){
		return fa[ll].cs+1;
	}
	if(t[xb].r<=ll||t[xb].l>=rr){
		return INT_MAX;
	}
	if(t[xb].l>=ll&&t[xb].r<=rr){
		return t[xb].sum;
	}
	return min(find_(xb*2,ll,rr),find_(xb*2+1,ll,rr));
}


int main(){
	freopen("query.in","r",stdin);
	freopen("query.out","w",stdout);
	memset(h,-1,sizeof(h));
	cin>>n;
	int x,y;
	for(int i=1;i<n;i++){
		scanf("%d%d",&x,&y);
		e[++cnt]=y;
		ne[cnt]=h[x];
		h[x]=cnt;
		e[++cnt]=x;
		ne[cnt]=h[y];
		h[y]=cnt;
	}
	fa[1].sum=-1;
	fa[1].cs=0;
	dfs(1,1);
	build(1,n,1);
	cin>>q;
	while(q--){
		cin>>l1>>r1>>k;
		ans=INT_MIN;
		for(int i=l1;i+k-1<=r1;i++){
			ans=max(ans,find_(1,i,i+k-1));
		}
		cout<<ans<<endl;
	}
	return 0;
} 
