#include<bits/stdc++.h>
using namespace std;
const int N = 5e5+10;
int n,q,dep[N],a[N<<1],pos[N],cnt;
int f[N<<1][21];
vector<int> e[N];
void dfs(int u,int fa){
	//cout<<u<<" ";
	dep[u]=dep[fa]+1;
	a[++cnt]=u;
	pos[u]=cnt;
	for(int v:e[u]){
		if(v==fa)continue;
		dfs(v,u);
		a[++cnt]=u;
	}
}
int lg[N<<1];
void st(){
	lg[1]=0;
	for(int i = 2;i<N;++i){
		lg[i]=lg[i/2]+1;
	}
	for(int i = 1;i<=cnt;++i){
		f[i][0]=a[i];
	}
	for(int k = 1;k<=20;++k){
		for(int i = 1;i+(1<<k)-1<=cnt;++i){
			if(dep[f[i][k-1]]<dep[f[i+(1<<(k-1))][k-1]]){
				f[i][k]=f[i][k-1];
			}else{
				f[i][k]=f[i+(1<<(k-1))][k-1];
			}
		}
	}
//	for(int i = 1;i<=cnt;++i){
//		cout<<a[cnt]<<" ";
//	}cout<<endl;
//	for(int i = 1;i<=n;++i){
//		for(int k = 0;k<=2;++k){
//			cout<<i<<" "<<k<<" "<<f[i][k]<<endl;
//		}
//	}
}
int lca(int x,int y){
	if(x==y)return x;
	if(pos[x]>pos[y]){
		swap(x,y);
	}
	int k = lg[pos[y]-pos[x]+1];
	if(dep[f[pos[x]][k]]<dep[f[pos[y]-(1<<k)+1][k]]){
		return f[pos[x]][k];
	}else{
		return f[pos[y]-(1<<k)+1][k];
	}
}
int main(){
	freopen("query.in","r",stdin);
	freopen("query.out","w",stdout);
	scanf("%d",&n);
	for(int i = 1;i<n;++i){
		int x,y;
		scanf("%d%d",&x,&y);
		e[x].push_back(y);
		e[y].push_back(x);
	}
	dfs(1,0);
	//cout<<endl;
	st();
	scanf("%d",&q);
	while(q--){
		int l,r,k;
		scanf("%d%d%d",&l,&r,&k);
		if(k==r-l+1){
			printf("%d\n",dep[lca(l,r)]);
		}else{
			int ans = 0;
			for(int i = l;i<=r;++i){
				for(int j = i+k-1;j<=r;++j){
					ans = max(ans,dep[lca(i,j)]);
					//cout<<i<<" "<<j<<" "<<lca(i,j)<<endl; 
				}
			}
			printf("%d\n",ans);
		}
	}
	return 0;
}
/*
6
5 6
6 1
6 2
2 3
2 4
*/
