#include<iostream>
#include<vector>
#define ls p<<1
#define rs p<<1|1
#define mid ((l+r)>>1)
#define l(u) dfn[tp[u]]
#define r(u) dfn[u]
using namespace std;
const int N=5e5+5,inf=1e9;
int n,dep[N],dfn[N],DFN,tp[N],son[N],ed[N],m,fa[N],id[N],siz[N];
int mx[N<<2],tg[N<<2],ans;
bool cl[N<<2];
int tcnt;
vector<int>g[N];
void dfs1(int u,int ft){
	dep[u]=dep[ft]+1;
	siz[u]=1;
	fa[u]=ft;
	for(auto v:g[u]){
		if(v==ft)continue;
		dfs1(v,u);
		siz[u]+=siz[v];
		if(siz[v]>siz[son[u]])son[u]=v;
	}
}
void dfs2(int u,int ft,int x){
	tp[u]=x;
	id[ed[x]=dfn[u]=++DFN]=dep[u];
	if(son[u])dfs2(son[u],u,x);
	for(auto v:g[u]){
		if(v==ft||v==son[u])continue;
		dfs2(v,u,v);
	}
}
void pushdown(int p){
	if(cl[p]){
		mx[ls]=tg[ls]=mx[rs]=tg[rs]=cl[p]=0;
		cl[ls]=cl[rs]=1;
	}
	if(tg[p]){
		mx[ls]+=tg[p];
		tg[ls]+=tg[p];
		mx[rs]+=tg[p];
		tg[rs]+=tg[p];
		tg[p]=0;
	}
}
void modify(int p,int l,int r,int L,int R,int k){
	pushdown(p);
	if(L<=l&&r<=R){
		tg[p]+=k;
		mx[p]+=k;
		return;
	}
	pushdown(p);
	if(L<=mid)modify(ls,l, mid ,L,R,k);
	if(R> mid)modify(rs,mid+1,r,L,R,k);
	mx[p]=max(mx[ls],mx[rs]);
}
int find(int p,int l,int r,int L,int R,int k){
	if(mx[p]<k)return -inf;
	if(l==r)return id[l];
	pushdown(p);
	if(mx[rs]>=k)return find(rs,mid+1,r,L,R,k);
	else return find(ls,l,mid,L,R,k);
}
int update(int u,int x,int k){
	int ret=-inf;
	while(u){
		modify(1,1,n,l(u),r(u),x);
		if(k!=inf)ret=max(ret,find(1,1,n,l(u),r(u),k));
		u=fa[tp[u]];
	}
	if(ret==-inf)return 0;
	return ret;
}
int main(){int x,y,k;
	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){
		cin>>x>>y;
		g[x].push_back(y);
		g[y].push_back(x);
	}
	dfs1(1,0);
	dfs2(1,0,1);
	cin>>m;
	while(m--){
		cl[1]=1;mx[1]=tg[1]=0;
		ans=-inf;
		cin>>x>>y>>k;
		for(int i=x;i<x+k-1;++i)update(i,1,inf);
		ans=max(ans,update(x+k-1,1,k));
		for(int i=x+k;i<=y;++i){
			update(i-k,-1,inf);
			ans=max(ans,update(i,1,k));
		}
		cout<<ans<<"\n";
	}
	return 0;
}
