#include <bits/stdc++.h>
#define N 1000005
using namespace std;

int n, qq, tot;
int dep[N], la[N];
struct node
{
	int i, to, nxt;
}ljh[N];
struct sss
{
	int i, l, r, m;
}tre[N * 2];

void build (int n, int l, int r)
{
	tre[n].i = n; tre[n].l = l; tre[n].r = r;
	if (l == r) 
	{
		tre[n].m = dep[l];
		return ;
	}
	int mid = (l + r) >> 1;
	build (n * 2, l, mid); build (n * 2 + 1, mid + 1, r);
	tre[n].m = min (tre[n * 2 + 1].m, tre[n * 2].m);
}

void add (int x, int y)
{
	ljh[++ tot].i = x;
	ljh[tot].to = y;
	ljh[tot].nxt = la[x];
	la[x] = tot;
}

int ser (int n, int l, int r)
{
	if (tre[n].l >= l && tre[n].r <= r) return tre[n].m;
	int mid = (tre[n].l + tre[n].r) >> 1;
	if (mid >= l && mid + 1 <= r) return max (ser (n * 2, l, r), ser (n * 2 + 1, l, r));
	if (mid < l) return ser (n * 2 + 1, l, r);
	if (mid + 1 > r) return ser (n * 2, l, r);
}

void jump (int k)
{
	for (int i = la[k]; i; i = ljh[i].nxt)
	{
		int to = ljh[i].to;
//		printf ("to = %d      i = %d\n", to, ljh[i].i);
//		printf ("dep = %d   nxt = %d \n", dep[to], ljh[i].nxt);
		if (dep[to] != 0) continue;
		dep[to] = dep[ljh[i].i] + 1;
		jump (to);
	}
}

int main ()
{
	freopen ("query.in", "r", stdin);
	freopen ("query.out", "w", stdout);
	scanf ("%d", &n);
	for (int i = 1; i < n; ++ i)
	{
		int x, y;
		scanf ("%d%d", &x, &y);
		add (x, y); add (y, x);
	}
	dep[1] = 1;
//	printf ("0");
	jump (1);
//	printf ("1");
	build (1, 1, n);
//	printf ("2");
	scanf ("%d", &qq);
//	printf ("3");
	for (int i = 1; i <= qq; ++ i)
	{
		int l, r, k;
		scanf ("%d%d%d", &l, &r, &k);
		printf ("%d\n", ser (1, l, r));
	}
	return 0;
}
