#include<iostream>
#include<vector>
#include<cstdio>
using namespace std;
const int nn=5e5+1;
int n;
int q;
struct node{
	int dep;
	int fa;
	vector<int>edge;
}E[nn];
struct aty{
	int l,r,k;
}qq[nn];
bool vis[nn];
void _dep(int p,int deep){
	vis[p]=true;
	E[p].dep=deep;
	for(int i=0;i<E[p].edge.size();i++)
	if(vis[E[p].edge[i]]==0){
		E[E[p].edge[i]].fa=p;
		_dep(E[p].edge[i],deep+1);
	}
}
void solve(int ll,int rr){
	int maxnd=-1;
	for(int i=ll;i<=rr;i++)
	maxnd=max(maxnd,E[i].dep);
	printf("%d\n",maxnd);
}
int main(){
	freopen("query.in","r",stdin);
	freopen("query.out","w",stdout);
	scanf("%d",&n);
	int u,v;
	for(int i=1;i<=n-1;i++){
		scanf("%d%d",&u,&v);
		E[u].edge.push_back(v);
		E[v].edge.push_back(u);
	}
	scanf("%d",&q);
	for(int i=1;i<=q;i++)
	scanf("%d%d%d",&qq[i].l,&qq[i].r,&qq[i].k);
	_dep(1,1);
	for(int i=1;i<=q;i++){
		solve(qq[i].l,qq[i].r);//Âú×ãÐÔÖÊA
	}
	return 0;
}
