#include <bits/stdc++.h>
#define MAXN 100005
using ll = long long;
using namespace std;
const int mod = 1e9+7;
int n;
vector<int> vec[MAXN];
int fa[MAXN][20],st[MAXN][20];
int dep[MAXN];
int logn[MAXN];
void dfs(int x,int f){
	fa[x][0]=f;dep[x]=dep[f]+1;
	for(int i=1;i<20;i++)fa[x][i]=fa[fa[x][i-1]][i-1];
	for(int j : vec[x]){
		if(j==f)continue;
		dfs(j,x);
	}
}
int lca(int x,int y){
	if(dep[x]<dep[y])swap(x,y);
	for(int i=19;i>=0;i--){
		if(dep[fa[x][i]]>=dep[y])x=fa[x][i];
	}
	if(x==y)return x;
	for(int i=19;i>=0;i--){
		if(fa[x][i]!=fa[y][i])x=fa[x][i],y=fa[y][i];
	}
	return fa[x][0];
}
void Nightcode(){
	//Actually, Nightcode is a wrong translation from "Nightcord" in EN to ZH.
	logn[1]=0; 
	for(int i=2;i<=n;i++)logn[i]=logn[i/2]+1;
	for(int i=1;i<=n;i++)st[i][0]=i;
	for(int j=1;j<20;j++){
		for(int i=1;i+(1<<j)-1<=n;i++){
			st[i][j]=lca(st[i][j-1],st[i+(1<<(j-1))][j-1]);
		}
	}
}
int query(int l,int r){
	int g = logn[r-l+1];
	return lca(st[l][g],st[r-(1<<g)+1][g]);
}
int main(){
	freopen("query.in","r",stdin);
	freopen("query.out","w",stdout);
	cin.tie(nullptr)->sync_with_stdio(false);
	cin>>n;
	for(int i=1;i<n;i++){
		int u,v;cin>>u>>v;
		vec[u].push_back(v);
		vec[v].push_back(u); 
	}
	dfs(1,0);
	Nightcode();
	int q;cin>>q;
	while(q--){
		int l,r,k; cin>>l>>r>>k;
		int ans = 1;
		for(int i=l;i+k-1<=r;i++){
			ans=max(ans,dep[query(i,i+k-1)]);
		}
		cout<<ans<<"\n";
	} 
	return 0;
} 
