#include<bits/stdc++.h>
using namespace std;
const int N=5e5+3,Q=N,M=21;
int n,q,ln,x,y,z,ans;
int l1,last[2*N],t[N],t1[2*N];
void qmx(int &x,int y){x=max(x,y);return;}
void add(int x,int y){
	last[++l1]=t[x];
	t[x]=l1,t1[l1]=y;
	return;
}
int m,pl[N],pr[N],sz[N],dep[N];
void dfs(int x,int y){
	m++,pl[x]=m,pr[x]=m;
	dep[x]=dep[y]+1;
	for(int i=t[x];i;i=last[i]){
		int v=t1[i];
		if(v==y) continue;
		dfs(v,x);
		qmx(pr[x],pr[v]);
	}
	return;
}
int f1[N][M],f2[N][M];
int q1(int x,int y){
	int z=log2(y-x+1);
	return min(f1[x][z],f1[y-(1<<z)+1][z]);
}
int q2(int x,int y){
	int z=log2(y-x+1);
	return max(f2[x][z],f2[y-(1<<z)+1][z]);
}
void calc(int x,int y,int l,int r){
	qmx(ans,dep[x]);
	for(int i=t[x];i;i=last[i]){
		int v=t1[i];
		if(v==y) continue;
		if(pl[v]<=l&&pr[v]>=r) calc(v,x,l,r);
	}
	return;
}
int main(){
	freopen("query.in","r",stdin);
	freopen("query.out","w",stdout);
	scanf("%d",&n);ln=log2(n);
	for(int i=1;i<n;i++){
		scanf("%d%d",&x,&y);
		add(x,y),add(y,x);
	}
	m=0,dfs(1,0);
	for(int i=1;i<=n;i++){
		f1[i][0]=pl[i];
		f2[i][0]=pl[i];
	}
	for(int j=1;j<=ln;j++)
	for(int i=1;i+(1<<j)-1<=n;i++){
		int pi=i+(1<<(j-1));
		f1[i][j]=min(f1[i][j-1],f1[pi][j-1]);
		f2[i][j]=max(f2[i][j-1],f2[pi][j-1]);
	}
	scanf("%d",&q);
	for(int i=1;i<=q;i++){
		scanf("%d%d%d",&x,&y,&z);
		ans=0;
		for(int j=x;j<=y-z+1;j++){
			int k=j+z-1;
			calc(1,0,q1(j,k),q2(j,k));
		}
		printf("%d\n",ans);
	}
	return 0;
}
