#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
inline ll read()
{
	ll res = 0, f = 1; char ch = getchar();
	while (ch < '0' || ch > '9') f = (ch == '-' ? -1 : f), ch = getchar();
	while (ch >= '0' && ch <= '9') res = (res << 1) + (res << 3) + (ch ^ 48), ch = getchar();
	return res * f;
}
inline void write(ll x)
{
	if (x < 0) putchar('-'), x = -x;
	if (x > 9) write(x / 10);
	putchar(x % 10 + '0');
}
inline void writech(ll x, char ch) { write(x), putchar(ch); }
const int N = 5e5 + 5, M = 20;
vector<int> e[N];
int f[N][M];
int main()
{
	freopen("query.in", "r", stdin);
	freopen("query.out", "w", stdout);
	int n = read();
	for (int i = 1; i < n; i++)
	{
		int u = read(), v = read();
		e[u].push_back(v), e[v].push_back(u);
	}

	bool flag = (e[1].size() == 1);
	for (int i = 2; i <= n; i++)
	{
		if (e[i].size() != 2)
		{
			flag = false;
			break;
		}
	}
	if (flag)
	{
		int fa = 0, u = 1, dep = 1;
		while (u != fa)
		{
			f[u][0] = dep++;
			fa = u;
			for (int i = 0; i < e[u].size(); i++)
			{
				if (e[u][i] == fa) continue;
				u = e[u][i];
			}
		}
		int q = read();
		while (q--)
		{
			int l = read(), r = read(), k = read();
			writech(dep, '\n');
		}
	}
	return 0;
}

