#include<bits/stdc++.h>
#define ll long long
#define pii pair<int,int>
#define vi vector<int>
#define pb push_back
#define lowbit(x) x&-x
using namespace std;
const int N=5e5+10;
int ans;
vi G[N];
int n,m,T,dfn[N],tot,anc[N][20],dep[N];
inline int read(){
	int s=0,f=0;
	char ch=getchar();
	while(ch<'0'||ch>'9') f|=(ch=='-'),ch=getchar();
	while(ch<='9'&&ch>='0') s=(s<<3)+(s<<1)+(ch^48),ch=getchar();
	return f?-s:s;
}
inline void dfs(int x,int fa){
	dep[x]=dep[fa]+1;
	dfn[x]=++tot;anc[tot][0]=fa;
	for(int to:G[x]) if(to!=fa) dfs(to,x);
}
inline int cmax(int x,int y){return dfn[x]<dfn[y]?x:y;}
inline int lca(int u,int v){
	if(u==v) return u;
	if(dfn[u]>dfn[v]) swap(u,v);
	u=dfn[u]+1,v=dfn[v];
	int k=__lg(v-u+1);
	return cmax(anc[u][k],anc[v-(1<<k)+1][k]);
}
inline void init(){
	dfs(1,1);
	for(register int j=1;j<=19;++j){
		for(register int i=1;i+(1<<j)-1<=n;++i){
			anc[i][j]=cmax(anc[i][j-1],anc[i+(1<<j-1)][j-1]);
		}
	}
}
struct seg{
	int fa[N<<2];
		inline void build(int i=1,int l=1,int r=n){
		if(l<r){
			int mid=(l+r)>>1;
			build(i<<1,l,mid);
			build(i<<1|1,mid+1,r);
			fa[i]=lca(fa[i<<1],fa[i<<1|1]);
		}else{
			fa[i]=l;
		}
	}
	inline int query(int i,int l,int r,int tl=1,int tr=n){
		if(tl==l&&tr==r) return fa[i];
		int mid=(tl+tr)>>1;
		if(r<=mid) return query(i<<1,l,r,tl,mid);
		else if(l>mid) return query(i<<1|1,l,r,mid+1,tr);
		else return lca(query(i<<1,l,mid,tl,mid),query(i<<1|1,mid+1,r,mid+1,tr));
	}
}t;
struct node{
	int siz,mx,ml,mr;
}val[N<<5];
int ls[N<<5],rs[N<<5],pos[N],rt[N],cnt;
inline node operator + (node x,node y){
	node res={0,0,0,0};
	res.siz=x.siz+y.siz;
	res.ml=x.ml+(x.siz==x.ml)*y.ml;
	res.mr=y.mr+(y.siz==y.mr)*x.mr;
	res.mx=max({x.mx,y.mx,x.mr+y.ml});
	return res;
}
inline void pushup(int x){val[x]=val[ls[x]]+val[rs[x]];}
inline void build(int& x,int l,int r){
	if(!x) x=++cnt;
	if(l<r){
		int mid=(l+r)>>1;
		build(ls[x],l,mid);
		build(rs[x],mid+1,r);
		pushup(x);
	}else{
		val[x]={1,0,0,0};
	}
}
inline int modify(int x,int l,int r,int c){
	int nw=++cnt;
	ls[nw]=ls[x],rs[nw]=rs[x];
	if(l<r){
		int mid=(l+r)>>1;
		if(c<=mid) ls[nw]=modify(ls[x],l,mid,c);
		else rs[nw]=modify(rs[x],mid+1,r,c);
		pushup(nw);
	}else val[nw]={1,1,1,1};
	return nw;
}
inline node query(int x,int l,int r,int tl=1,int tr=n){
	if(l==tl&&r==tr) return val[x];
	int mid=(tl+tr)>>1;
	if(r<=mid) return query(ls[x],l,r,tl,mid);
	else if(l>mid) return query(rs[x],l,r,mid+1,tr);
	else return query(ls[x],l,mid,tl,mid)+query(rs[x],mid+1,r,mid+1,tr);
}
inline void solve1(){
	for(register int i=1;i<=n;++i) pos[i]=i;
	sort(pos+1,pos+n+1,[](int x,int y){return dep[x]<dep[y];});
	build(rt[n+1],1,n);
	for(register int i=n;i>=1;--i) rt[i]=modify(rt[i+1],1,n,pos[i]);
	T=read();
	while(T--){
		int L=read(),R=read(),k=read();
		int l=1,r=n-k+1;
		while(l<r){
			int mid=(l+r+1)>>1;
			if(query(rt[mid],L,R).mx>=k) l=mid;
			else r=mid-1;
		}
		cout<<l<<'\n';
	}
}
inline void solve2(){
	t.build();
	T=read();
	while(T--){
		int l=read(),r=read(),k=read();ans=0;
		for(register int i=l;i+k-1<=r;++i) ans=max(ans,dep[t.query(1,i,i+k-1)]);
		cout<<ans<<'\n';
	}
}
int main(){
	freopen("query.in","r",stdin);
	freopen("query.out","w",stdout);
	n=read();
	for(register int i=1;i<n;++i){
		int u=read(),v=read();
		G[u].pb(v),G[v].pb(u);
	}
	init();
	int s1=0,s2=0;
	for(register int i=1;i<=n;++i){
		s1+=((int)G[i].size()==1);
		s2+=((int)G[i].size()==2);
	}
	if(s1+s2==n&&s1==2) solve1();
	else solve2();
	return 0;
}
/*
3
1 3
3 2
3
1 2 1
1 2 2
1 1 1

*/
