#include<bits/stdc++.h>
using namespace std;
const int N=5e5+13;
int n,q;
vector<int>g[N];
namespace sub1{
	const int M=5012;
	int fa[M],dep[M],ans[M][M],top[M],siz[M],son[M];
	void dfs(int x,int F){
		fa[x]=F,dep[x]=dep[F]+1,siz[x]=1;
		for(int y:g[x]){
			if(y!=F)dfs(y,x),siz[x]+=siz[y],son[x]=siz[son[x]]>siz[y]?son[x]:y; 
		}
	}
	void dfs2(int x,int topf){
		top[x]=topf;
		if(!son[x])return ;
		dfs2(son[x],topf);
		for(int y:g[x]){
			if(y!=son[x]&&y!=fa[x])dfs2(y,y);
		}
	}
	int Lca(int x,int y){
		while(top[x]!=top[y]){
			if(dep[top[x]]<dep[top[y]])swap(x,y);
			x=fa[top[x]];
		}
		return dep[x]<dep[y]?x:y;
	}
	void solve(){
		dfs(1,0);
		dfs2(1,1);
		for(int i=1;i<=n;++i){
			ans[i][i]=i;
			for(int j=i+1;j<=n;++j)ans[i][j]=Lca(ans[i][j-1],j);
		}
		cin>>q;
		while(q--){
			int l,r,k;cin>>l>>r>>k;
			int res=0;
			for(int i=l;i+k-1<=r;++i)res=max(res,dep[ans[i][i+k-1]]);
			cout<<res<<'\n';
		}
	}
}
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;
	for(int i=1;i<n;++i){
		int u,v;cin>>u>>v;
		g[u].push_back(v),g[v].push_back(u);
	}
	if(n<=5000){sub1::solve();return 0;}
	return 0;
}
