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

#define ll long long
#define INF 0x3f3f3f3f

int rd()
{
	int x = 0,f= 1;
	char c= getchar();
	while (c < '0' || c > '9')
	{
		if (c == '-') f = -1;
		c = getchar();
	}
	while (c >= '0' && c <= '9') x = (x<<1)+(x<<3) +(c^48),c = getchar();
	return x * f;
}

const int N = 1e6+5;


int n,q;
vector<int> v[N];

int eul[N],tot,fst[N];

int dep[N];

void dfs(int x,int fa)
{
	tot++;
	dep[x] = dep[fa] + 1;
	fst[x] = tot;
	eul[tot] = dep[x];
	for (auto y : v[x])
	{
		if (y== fa) continue;
		dfs(y,x);
		tot++;eul[tot] = dep[x];
	}
}

int f[N][25];
int mn[N][25],mx[N][25];
void prework()
{
	for (int i = 1;i <= tot;i++) f[i][0] = eul[i];
	for (int j = 1;j <= 20;j++)
		for (int i = 1;(i+(1<<j)-1) <= tot;i++)
			f[i][j] = min(f[i][j-1],f[i+(1<<(j-1))][j-1]);
	for (int i = 1;i <= n;i++) mn[i][0]=mx[i][0] = fst[i];
	for (int j = 1;j <= 20;j++)
		for (int i = 1;(i+(1<<j)-1) <= n;i++)
			mn[i][j] = min(mn[i][j-1],mn[i+(1<<(j-1))][j-1]),
			mx[i][j] = max(mx[i][j-1],mx[i+(1<<(j-1))][j-1]);
}

int query(int l,int r)
{
	int k = (int)(log(r-l+1)/log(2));
	return min(f[l][k],f[r-(1<<k)+1][k]);
}
int querymx(int l,int r)
{
	int k = (int)(log(r-l+1)/log(2));
	return max(mx[l][k],mx[r-(1<<k)+1][k]);
}
int querymn(int l,int r)
{
	int k = (int)(log(r-l+1)/log(2));
	return min(mn[l][k],mn[r-(1<<k)+1][k]);
}


void solve5000()
{
	while (q--)
	{
		int l =rd(),r = rd(),k = rd();
		int ans = 0;
		for (int i = l;i+k-1 <= r;i++)
		{
			int L = i,R = i + k -1;
			int fL = querymn(L,R);
			int fR = querymx(L,R);
			ans = max(ans,query(fL,fR));
		}
		printf("%d\n",ans);
	}
}

struct node
{
	int l,r,k;
}Q[N];

void solveB()
{
	for (int i = 1;i <= q;i++)
	{
		int l = Q[i].l,r = Q[i].r,k = Q[i].k;
		int fL = querymn(l,r);
		int fR = querymx(l,r);
		printf("%d\n",query(fL,fR));
	}
}

int main()
{
	freopen("query.in","r",stdin);
	freopen("query.out","w",stdout);
	cin >> n;
	for (int i = 1;i <= n-1;i++)
	{
		int x = rd(),y =rd();
		v[x].push_back(y);v[y].push_back(x);
	}
	dfs(1,0);
//	for (int i = 1;i <= tot;i++) cout << fst[i] << ' ' << eul[i] << endl;
	cin >> q;
	prework();
	if (n <= 5000)
	{
		solve5000();
		return 0;
	}
	bool flag = 1;
	for (int i = 1;i <= q;i++) Q[i].l = rd(),Q[i].r =rd(),Q[i].k =rd(),flag &= (Q[i].k==(Q[i].r-Q[i].l+1));
	if (flag)
	{
		solveB();
		return 0;
	}
	
	puts("1");
	return 0;
}
/*
6
5 6
6 1
6 2
2 3
2 4
3
2 5 4
1 4 4
1 6 6

*/

