#include<bits/stdc++.h>
#define lc k<<1
#define rc k<<1|1
using namespace std;
const int N=5e5;
int n,q,ans,fa[N+5],dep[N+5],lst[N+5],hv[N+5],td[N+5];
int ct=0,dfn[2*N+5],fr[N+5],lt[N+5],tr1[4*N+5],tr2[4*N+5],st[2*N+5][25];
vector<int>G[N+5];
void ch(int k,int l,int r,int x,int v){
	if(l==r&&l==x){
		tr1[k]=tr2[k]=v;
		return;
	}
	int mid=l+r>>1;
	if(x<=mid) ch(lc,l,mid,x,v);
	else ch(rc,mid+1,r,x,v);
	tr1[k]=min(tr1[lc],tr1[rc]);
	tr2[k]=max(tr2[lc],tr2[rc]);
}
int gtmn(int k,int l,int r,int x,int y){
	if(l>=x&&r<=y) return tr1[k];
	int mid=l+r>>1,re=1e9;
	if(x<=mid) re=min(re,gtmn(lc,l,mid,x,y));
	if(y>mid) re=min(re,gtmn(rc,mid+1,r,x,y));
	return re;
}
int gtmx(int k,int l,int r,int x,int y){
	if(l>=x&&r<=y) return tr2[k];
	int mid=l+r>>1,re=0;
	if(x<=mid) re=max(re,gtmx(lc,l,mid,x,y));
	if(y>mid) re=max(re,gtmx(rc,mid+1,r,x,y));
	return re;
}
int gtst(int l,int r){
	int o=__lg(r-l+1);
	return min(st[l][o],st[r-(1<<o)+1][o]);
}
void dfs(int u,int f){
	fa[u]=f;
	dep[u]=dep[f]+1;
	dfn[++ct]=dep[u];
	fr[u]=ct;
	ch(1,1,n,u,fr[u]);
	for(int v:G[u]){
		if(v==f) continue;
		dfs(v,u);
		dfn[++ct]=dep[u];
		lt[u]=ct;
	}
}
void up(int u,int w){
	if(lst[u]==w-1) ++hv[u];
	else hv[u]=1;
	td[u]=max(td[u],hv[u]);
	lst[u]=w;
	if(fa[u]) up(fa[u],w);
}
int main()
{
	freopen("query.in","r",stdin);
	freopen("query.out","w",stdout);
	scanf("%d",&n);
	for(int i=1,x,y;i<n;i++){
		scanf("%d%d",&x,&y);
		G[x].push_back(y);
		G[y].push_back(x);
	}
	dfs(1,0);
	if(n<=5000&&q<=5000){
		scanf("%d",&q);
		while(q--){
			int l,r,k;
			scanf("%d%d%d",&l,&r,&k);
			for(int i=1;i<=n;i++){
				lst[i]=hv[i]=td[i]=0;
			}
			for(int i=l;i<=r;i++){
				up(i,i);
			}
			ans=0;
			for(int i=1;i<=n;i++){
				if(td[i]>=k) ans=max(ans,dep[i]);
			}
			printf("%d\n",ans);
		}
		return 0;
	}
	for(int i=1;i<=ct;i++){
		st[i][0]=dfn[i];
	}
	for(int j=1;j<=20;j++){
		for(int i=1;i+(1<<j)-1<=ct;i++){
			st[i][j]=min(st[i][j-1],st[i+(1<<j-1)][j-1]);
		}
	}
	scanf("%d",&q);
	while(q--){
		int l,r,k;
		scanf("%d%d%d",&l,&r,&k);
		if(k==r-l+1){
			int vl=gtmn(1,1,n,l,r),vr=gtmx(1,1,n,l,r);
			ans=gtst(vl,vr);
			printf("%d\n",ans);
			continue;
		}
	}
	return 0;
}
