#include <bits/stdc++.h>
using namespace std;
vector<int>tr[500005];
int dfn[500005],siz[500005],top[500005],dpt[500005],son[500005],par[500005],rev[500005],ptr;
void dfs1(int x,int pa){
	int deg=tr[x].size();
	siz[x]=1;par[x]=pa;dpt[x]=dpt[pa]+1;
	for(int i=0;i<deg;i++){
		if(tr[x][i]==pa)continue;
		dfs1(tr[x][i],x);
		siz[x]+=siz[tr[x][i]];
		if(siz[tr[x][i]]>siz[son[x]])son[x]=tr[x][i];
	}
}
void dfs2(int x,int tp){
	dfn[x]=++ptr;
	rev[ptr]=x;
	top[x]=tp;
	int deg=tr[x].size();
	if(son[x])dfs2(son[x],tp);
	for(int i=0;i<deg;i++){
		if(tr[x][i]==par[x])continue;
		if(tr[x][i]==son[x])continue;
		dfs2(tr[x][i],tr[x][i]);
	}
}
struct seg{
	int l,r,d;
}sgt[2000005];

int lca(int x,int y){
	while(top[x]!=top[y]){
		if(dpt[top[x]]>dpt[top[y]])swap(x,y);
		y=par[top[y]];
	}
	if(dpt[x]>dpt[y])swap(x,y);
	return x;
}

void build(int l,int r,int id){
	int mid=(l+r)>>1; 
	sgt[id].l=l;sgt[id].r=r;
	if(l==r){sgt[id].d=l;return ;}
	build(l,mid,id<<1);
	build(mid+1,r,id<<1|1);
	sgt[id].d=lca(sgt[id<<1].d,sgt[id<<1|1].d);
}

int query(int id,int l,int r){
	if(l>sgt[id].r||r<sgt[id].l)return 0;
	if(l<=sgt[id].l&&r>=sgt[id].r){
		return sgt[id].d;
	}
	int l1=query(id<<1,l,r),r1=query(id<<1|1,l,r);
	if(!l1)return r1;
	if(!r1)return l1;
	return lca(l1,r1);
}

void subt1(int l,int r,int k){
	int res=0;
	for(int i=l;i<=r;i++){
		int ans=0;
		for(int j=i;j<=r;j++){
			if(!ans)ans=lca(i,j);
			else ans=lca(ans,j);
			if(j==k)break;
		}
		if(ans)	res=max(res,dpt[ans]);
//		cout<<
		else break;
	}
	cout<<res<<endl;
}

void subt2(int l,int r,int k){
	cout<<dpt[query(1,l,r)] <<endl;
}

int main(){
	freopen("query.in","r",stdin);
	freopen("query.out","w",stdout);
	int n,q;cin>>n;
	for(int i=1;i<n;i++){
		int u,v;cin>>u>>v;
		tr[u].push_back(v);
		tr[v].push_back(u);
	}
	dfs1(1,0);dfs2(1,1);build(1,n,1);
	cin>>q;
	while(q--){
		int l,r,k;
		cin>>l>>r>>k;
		if(l+k==r+1)subt2(l,r,k);
		else if(r-l<=5000)subt1(l,r,k);
	}
	return 0;
}
