#include<bits/stdc++.h>
using namespace std;
#define max_n 500000
int lg[max_n+2];
int n;
int q;
vector<int>g[max_n+2];
int fa[max_n+2];
int de[max_n+2];
int dfn[max_n+2],tim=0;
int rk[max_n+2];
int sti[22][max_n+2];
int sta[22][max_n+2];
int stf[22][max_n+2];
int ans=0;
void dfs(int u,int f){
	fa[u]=f; de[u]=de[f]+1; dfn[u]=++tim; rk[dfn[u]]=u;
	for(auto v:g[u]){
		if(v!=f)dfs(v,u);
	}
}
inline int cmpde(int u,int v){return (de[u]<=de[v])?u:v;}
inline int queryi(int l,int r){
	int len=lg[r-l+1];
	return min(sti[len][l],sti[len][r-(1<<len)+1]);
}
inline int querya(int l,int r){
	int len=lg[r-l+1];
	return max(sta[len][l],sta[len][r-(1<<len)+1]);
}
inline int asklca(int u,int v){
	if(u==v)return u;
	if((u=dfn[u])>(v=dfn[v]))swap(u,v);
	int len=lg[v-u++];
	return cmpde(stf[len][u],stf[len][v-(1<<len)+1]); 
}
namespace SUBA{
	struct W{
		int len;
		int lma,rma,ma;
	};
	struct T{
		int ls,rs;
		W s;
	}tr[max_n*32+2];
	int ti=0,rt[max_n+2];
	bool check(){
		if((int)g[1].size()>1)return false;
		int cnt=0;
		for(int i=1;i<=n;++i){
			if((int)g[i].size()>1)++cnt;
		}
		return cnt<=2;
	}
	inline W operator+(W a,W b){
		W res; res.len=a.len+b.len;
		res.lma=a.lma; if(a.ma==a.len)res.lma=a.ma+b.lma;
		res.rma=b.rma; if(b.ma==b.len)res.rma=b.ma+a.rma;
		res.ma=max(max(a.ma,b.ma),a.rma+b.lma);
		return res;
	}
	void upd(int &o,int o2,int l,int r,int x){
		if(!o)o=++ti;
		if(l>=r){tr[o].s=(W){1,1,1,1}; return;}
		int mid=(l+r)>>1;
		if(x<=mid){upd(tr[o].ls,tr[o2].ls,l,mid,x); tr[o].rs=tr[o2].rs;}
		else{upd(tr[o].rs,tr[o2].rs,mid+1,r,x); tr[o].ls=tr[o2].ls;}
		tr[o].s=tr[tr[o].ls].s+tr[tr[o].rs].s;
	}
	W query(int o,int l,int r,int ql,int qr){
		if(!o)return (W){0,0,0,0};
		if(ql<=l&&r<=qr)return tr[o].s;
		int mid=(l+r)>>1;
		if(qr<=mid)return query(tr[o].ls,l,mid,ql,qr);
		if(ql>mid)return query(tr[o].rs,mid+1,r,ql,qr);
		return query(tr[o].ls,l,mid,ql,qr)+query(tr[o].rs,mid+1,r,ql,qr);
	}
	void work(){
		rt[n+1]=0;
		for(int i=n;i>=1;--i)upd(rt[n],rt[n+1],1,n,rk[i]);
		for(int ca=1,l,r,k;ca<=q;++ca){
			scanf("%d%d%d",&l,&r,&k);
			ans=0;
			for(int ql=1,qr=n,mid;ql<=qr;){
				mid=(ql+qr)>>1;
				if(query(rt[mid],1,n,l,r).ma>=k){ans=mid; ql=mid+1;}
				else qr=mid-1;
			}
			printf("%d\n",ans);
		}
	}
}
int main(){
	freopen("query.in","r",stdin);
	freopen("query.out","w",stdout);
	for(int i=2;i<=max_n;++i)lg[i]=lg[i>>1]+1;
	scanf("%d",&n);
	for(int i=1,u,v;i<n;++i){
		scanf("%d%d",&u,&v);
		g[u].push_back(v); g[v].push_back(u);
	}
	scanf("%d",&q);
	dfs(1,0);
	for(int i=1;i<=n;++i){
		sti[0][i]=sta[0][i]=dfn[i]; stf[0][i]=fa[rk[i]];
	}
	for(int j=1;j<=20;++j){
		for(int i=1;i+(1<<j)-1<=n;++i){
			sti[j][i]=min(sti[j-1][i],sti[j-1][i+(1<<(j-1))]);
			sta[j][i]=max(sta[j-1][i],sta[j-1][i+(1<<(j-1))]);
			stf[j][i]=cmpde(stf[j-1][i],stf[j-1][i+(1<<(j-1))]);
		}
	}
	if(SUBA::check()){SUBA::work(); return 0;}
	for(int ca=1,l,r,k;ca<=q;++ca){
		scanf("%d%d%d",&l,&r,&k);
		ans=0;
		for(int i=l;i<=r-k+1;++i){
			int x=rk[queryi(i,i+k-1)];
			int y=rk[querya(i,i+k-1)];
			ans=max(ans,de[asklca(x,y)]);
		}
		printf("%d\n",ans);
	}
	return 0;
}

