#include<bits/stdc++.h>
using namespace std;
const int N=5e5+5;
struct node{
	int l,r,mx;
}tree[4*N];
int dep[N],k,l,r,n,q;
void build(int k,int l,int r){
	tree[k].l = l;
	tree[k].r = r;
	if(l>=r){
		tree[k].mx = dep[l];
		return ;
	}
	int lc = 2*k;
	int rc = 2*k+1;
	int mid = (l+r)/2;
	build(lc,l,mid);
	build(rc,mid+1,r);
	tree[k].mx = max(tree[lc].mx,tree[rc].mx);
} 
int query(int k,int l,int r){
	if(tree[k].l>=l&&tree[k].r<=r){
		return tree[k].mx;
	}
	int lc = 2*k;
	int rc = 2*k+1;
	int mid = (tree[k].l+tree[k].r)/2;
	int ans=0;
	if(l<=mid){
		ans = max(ans,query(lc,l,r));
	}
	if(r>mid){
		ans = max(ans,query(rc,l,r));
	}
	return ans;
}
int cnt,f[N],fir[N],nex[2*N],en[2*N];
void add(int u,int v){
	cnt++; 
	nex[cnt] = fir[u];
	fir[u] = cnt;
	en[cnt] = v;
}
void dfs(int u){
	for(int t=fir[u];t;t=nex[t]){
		int v = en[t];
		if(v==f[u]) continue;
		dep[v] = dep[u]+1;
		f[v] = u;
		dfs(en[t]);
	}
}
int main(){
	freopen("query.in","r",stdin);
	freopen("query.out","w",stdout);
	scanf("%d",&n);
	for(int i=1;i<n;i++){
		int u,v;
		scanf("%d%d",&u,&v);
		add(u,v);
		add(v,u);
	}
	dep[1] = 1;
	dfs(1);
	build(1,1,n);
	scanf("%d",&q);
	for(int i=1;i<=q;i++){
		scanf("%d%d%d",&l,&r,&k);
		printf("%d\n",query(1,l,r));
	}
	fclose(stdin);
	fclose(stdout); 
	return 0;
}

/*
12:50
唔...终于还是放弃挣扎了
本来退役一年再回来比赛就没指望拿什么奖
但结果连个三等都拿不到还是挺难绷的 
还有不到两百天高考，希望whk能顺利吧QAQ
*/ 
