#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;

struct ty
{
	int lsum, rsum, maxn;
	bool sum;
	ty operator + (ty x)
	{
		ty y;
		y.sum = sum | x.sum;
		y.lsum = sum ? lsum : lsum + x.lsum;
		y.rsum = x.sum ? x.rsum : x.rsum + rsum;
		y.maxn = max(max(maxn, x.maxn), rsum + x.lsum);
		return y;
	}
};

struct node
{
	int lc, rc;
	ty x;
};

int dep[500010];
int f[500010][20];
int g[500010][20];
int a[500010];
int lg2[1000010];
int rt[500010];
vector<int> G[500010];
int n, tot, q;
pair<int, int> b[500010];
node tr[12000010];

void dfs(int u)
{
	dep[u] = dep[f[u][0]] + 1;
	for(int i = 1; i < 20; i++) f[u][i] = f[f[u][i - 1]][i - 1];
	for(int v : G[u])
	{
		if(v != f[u][0])
		{
			f[v][0] = u;
			dfs(v);
		}
	}
}

int lca(int u, int v)
{
	if(dep[u] < dep[v]) swap(u, v);
	while(dep[u] > dep[v]) u = f[u][lg2[dep[u] - dep[v]]];
	if(u == v) return u;
	for(int i = 19; i >= 0; i--)
	{
		if(f[u][i] != f[v][i])
		{
			u = f[u][i];
			v = f[v][i];
		}
	}
	return f[u][0];
}

void build(int &o, int l, int r)
{
	o = ++tot;
	if(l == r)
	{
		tr[o].x.sum = 1;
		tr[o].x.maxn = tr[o].x.lsum = tr[o].x.rsum = 0;
		return;
	}
	int mid = l + r >> 1;
	build(tr[o].lc, l, mid);
	build(tr[o].rc, mid + 1, r);
	tr[o].x = tr[tr[o].lc].x + tr[tr[o].rc].x;
}

void modify(int &o1, int o2, int l, int r, int p, int k)
{
	o1 = ++tot;
	tr[o1] = tr[o2];
//	printf("modify: %d %d %d %d %d %d\n", o1, o2, l, r, p, k);
	if(l == r)
	{
		tr[o1].x.sum = k;
		tr[o1].x.maxn = tr[o1].x.lsum = tr[o1].x.rsum = (k == 0);
		return;
	}
	int mid = l + r >> 1;
	if(p <= mid) modify(tr[o1].lc, tr[o2].lc, l, mid, p, k);
	else modify(tr[o1].rc, tr[o2].rc, mid + 1, r, p, k);
	tr[o1].x = tr[tr[o1].lc].x + tr[tr[o1].rc].x;
}

ty query(int o, int l, int r, int L, int R)
{
//	printf("query: %d %d %d %d %d %d %d\n", o, l, r, L, R, tr[o].lc, tr[o].rc);
	if(L <= l && r <= R) return tr[o].x;
	ty res;
	res.lsum = res.maxn = res.rsum = res.sum = 0;
	int mid = l + r >> 1;
//	printf("mid -> %d\n", mid);
	if(L <= mid) res = query(tr[o].lc, l, mid, L, R);
	if(mid < R) res = res + query(tr[o].rc, mid + 1, r, L, R);
	return res;
}


bool cmp(pair<int, int> x, pair<int, int> y)
{
	return x > y;
}

void init()
{
	for(int i = 1; i <= n; i++) g[i][0] = dep[i];
	for(int k = 1; k < 20; k++)
	{
		for(int i = 1; i <= n; i++)
		{
			g[i][k] = max(g[i][k - 1], g[i + (1 << k - 1)][k - 1]);
		}
	}
}

int query2(int l, int r)
{
	int k = lg2[r - l + 1];
	return max(g[l][k], g[r - (1 << k) + 1][k]);
}

int main()
{
	freopen("query.in", "r", stdin);
	freopen("query.out", "w", stdout);
	for(int i = 2; i <= 1000000; i++) lg2[i] = lg2[i >> 1] + 1;
	scanf("%d", &n);
	for(int i = 1; i < n; i++)
	{
		int u, v;
		scanf("%d%d", &u, &v);
		G[u].push_back(v);
		G[v].push_back(u);
	}
	dfs(1);
	
	init();
	
	n--;
	for(int i = 1; i <= n; i++)
	{
		a[i] = dep[lca(i, i + 1)];
		b[i] = {a[i], i};
	}
	
	sort(b + 1, b + n + 1, cmp);
	
//	for(int i = 1; i <= n; i++)
//	{
//		printf("(%d %d)\n", b[i].first, b[i].second);
//	}
	
	build(rt[0], 1, n);
	for(int i = 1; i <= n; i++)
	{
		modify(rt[i], rt[i - 1], 1, n, b[i].second, 0);
//		print(rt[i], 1, n);
	}
	scanf("%d", &q);
	
//	printf("asdasfd\n");
	
	for(int i = 1; i <= q; i++)
	{
//		printf("%d\n", i);
		int ql, qr, k;
		scanf("%d%d%d", &ql, &qr, &k);
		if(k == 1)
		{
			printf("%d\n", query2(ql, qr));
		}
		else
		{
			qr--;
			k--;
			int l = 1, r = n + 1;
			while(l < r)
			{
				int mid = l + r >> 1;
				if(query(rt[mid], 1, n, ql, qr).maxn >= k) r = mid;
				else l = mid + 1;
			}
			printf("%d\n", b[r].first);
		}
	}
	return 0;
}
