#include <bits/stdc++.h>
#define ll long long
#define pii pair<int,int>
#define fo(i,a,b) for(int i=(a);i<=(b);i++)
#define de(i,a,b) for(int i=(a);i>=(b);i--)
using namespace std;
const ll N=5e5+50,M=+50,L=0;
const ll inf=1e9,P=0;
ll read(){
	ll x=0,f=0;char c=getchar();
	while(c<'0'||c>'9') f|=(c=='-'),c=getchar();
	while('0'<=c&&c<='9') x=x*10+c-'0',c=getchar();
	return f?-x:x;
}
int n,q,timer;
int mn[N<<1][21],in[N],out[N],st[N][20],dep[N],lg[N<<1];
vector<int> G[N];
#define qmn(a,b) (dep[a]<dep[b]?a:b)
void dfs(int x,int f){
	dep[x]=dep[f]+1;
	mn[++timer][0]=x,in[x]=out[x]=timer;
	for(int v:G[x]) if(v!=f) 
		dfs(v,x),mn[++timer][0]=x,out[x]=timer;	
}
//int lca(int a,int b){
//	if(dep[a]<dep[b]) swap(a,b);
//	de(i,19,0) if(dep[fa[a][i]]>=dep[b]) a=fa[a][i];
//	de(i,19,0) if(fa[a][i]!=fa[b][i]) a=fa[a][i],b=fa[b][i];
//	return a==b?a:fa[a][0];
//}
int lca(int a,int b){
	if(in[a]>in[b]) swap(a,b);
	if(in[a]<=in[b]&&in[b]<=out[a]) return a;
//	cout<<in[b]<<" "<<out[a]<<endl;
	int k=lg[in[b]-out[a]+1];
	return qmn(mn[out[a]][k],mn[in[b]-(1<<k)+1][k]);
}
int qry(int l,int r){
	int k=lg[r-l+1];
	return lca(st[l][k],st[r-(1<<k)+1][k]);
}
signed main(){
	freopen("query.in","r",stdin);
	freopen("query.out","w",stdout);
	n=read();
	fo(i,1,n-1){
		int u=read(),v=read();
		G[u].push_back(v),G[v].push_back(u);
	}
	lg[1]=0;
	fo(i,2,n<<1) lg[i]=lg[i>>1]+1;
	dfs(1,0);
//	fo(j,1,19) fo(i,1,n)
//		fa[i][j]=fa[fa[i][j-1]][j-1];
	fo(j,1,20) fo(i,1,n*2-(1<<j)+1)	
		mn[i][j]=qmn(mn[i][j-1],mn[i+(1<<j-1)][j-1]);
	fo(i,1,n) st[i][0]=i;
	fo(j,1,19) fo(i,1,n-(1<<j)+1)
		st[i][j]=lca(st[i][j-1],st[i+(1<<j-1)][j-1]);
//	fo(i,1,2*n) cout<<mn[i][0]<<endl;
	q=read();
	while(q--){
		int l=read(),r=read(),k=read();
		int ans=0;
		fo(i,l,r-k+1){
			int res=qry(i,i+k-1);
			if(dep[res]>dep[ans]) ans=res;
		}
		printf("%d\n",dep[ans]);
	}
	return 0;
}
