# include<iostream>
# include<cstdio>
using namespace std;

const int N=5002;
int n,u,v,q,l,r,k,tmp;
int cnt,head[N],to[N],nxt[N];
int dep[N],f[N][15]; //结点i往上2^j个的祖先 
int log2[N];
int ans[N][N],anss;

void add(int u,int v){
	to[++cnt]=v;
	nxt[cnt]=head[u];
	head[u]=cnt;
}

void build(int u){
	for(int i=head[u];i;i=nxt[i]){
		int v=to[i];
		if(v!=f[u][0]){
			dep[v]=dep[u]+1;
			f[v][0]=u;
			for(int j=1;j<=log2[dep[v]];++j)
				f[v][j]=f[f[v][j-1]][j-1];
			build(v);
		}
	}
}

int LCA(int u,int v){
	if(dep[u]>dep[v]){
		tmp=u;
		u=v;
		v=tmp;
	}
	if(dep[u]<dep[v])
		while(dep[v]-dep[u])
			v=f[v][log2[dep[v]-dep[u]]];
	for(int i=log2[dep[u]];i>=0;i--)
		if(f[u][i]!=f[v][i])
			u=f[u][i],v=f[v][i];
	return (u==v?u:f[u][0]);
}

int main(){
	freopen("query.in","r",stdin);
	freopen("query.out","w",stdout);
	ios::sync_with_stdio(0);
	cin.tie(0),cout.tie(0);
	cin>>n;
	dep[1]=1;
	for(int i=2;i<=n;++i)
		log2[i]=log2[i/2]+1;
	for(int i=1;i<n;++i){
		cin>>u>>v;
		add(u,v);
		add(v,u);
	}
	build(1);
	for(int i=1;i<=n;++i)
		for(int j=i;j<=n;++j){
			if(j==i) ans[i][j]=i;
			else ans[i][j]=LCA(ans[i][j-1],j);
		}
	cin>>q;
	while(q--){
		anss=0;
		cin>>l>>r>>k;
		for(int i=l;i<=r-k+1;++i)
			if(dep[ans[i][i+k-1]]>anss)
				anss=dep[ans[i][i+k-1]];
		cout<<anss<<endl;
	}
	return 0;
}
