#include <bits/stdc++.h>
using namespace std;
const int N = 5e5 + 5;
int n,q,m,tot,head[N],to[N],nxt[N],dep[N],dfn[N],e[N << 1],st[N << 1][20],lg[N << 1],st2[N][20],L[N],R[N],M[N],p[N];
vector <int> v[N];
struct Qry{int l,r,k;} a[N];
bool cmp(int x,int y){return dep[x] < dep[y];}
bool checkA()
{
	if(v[1].size() > 1) return false;
	for(int i = 2;i <= n;i++) if(v[i].size() > 2) return false;
	return true;
}
void dfs(int x,int lst)
{
	e[++tot] = x,dfn[x] = tot,dep[x] = dep[lst] + 1;
	for(int y : v[x])
	{
		if(y == lst) continue;
		dfs(y,x),e[++tot] = x;
	}
}
int minp(int x,int y){return (dep[x] < dep[y] ? x : y);}
void build()
{
	for(int i = 2;i <= tot;i++) lg[i] = lg[i >> 1] + 1;
	for(int i = 1;i <= tot;i++) st[i][0] = e[i];
	for(int j = 1;j <= lg[tot];j++)
		for(int i = 1;i + (1 << j) - 1 <= tot;i++)
			st[i][j] = minp(st[i][j - 1],st[i + (1 << (j - 1))][j - 1]);
}
int lca(int x,int y)
{
	x = dfn[x],y = dfn[y];
	if(x > y) swap(x,y);
	int t = lg[y - x + 1];
	return minp(st[x][t],st[y - (1 << t) + 1][t]);
}
void build2()
{
	for(int i = 1;i <= n;i++) st2[i][0] = i;
	for(int j = 1;j <= lg[n];j++)
		for(int i = 1;i + (1 << j) - 1 <= n;i++)
			st2[i][j] = lca(st2[i][j - 1],st2[i + (1 << (j - 1))][j - 1]);
}
int query(int l,int r)
{
	int t = lg[r - l + 1];
	return lca(st2[l][t],st2[r - (1 << t) + 1][t]);
}
struct Node{int len,f,l,r;} t[N << 2];
Node operator + (Node x,Node y)
{
	Node ret;
	ret.len = x.len + y.len;
	ret.f = max(x.f,y.f);
	ret.l = x.l;
	ret.r = y.r;
	if(x.l == x.len)
	{
		ret.f = max(ret.f,x.l + y.l);
		ret.l = x.l + y.l;
	}
	if(y.l == y.len)
	{
		ret.f = max(ret.f,x.r + y.l);
		ret.r = x.r + y.l;
	}
	return ret;
}
struct SgT
{
	#define ls (x << 1)
	#define rs (ls | 1)
	#define mid ((l + r) >> 1)
	void build(int x,int l,int r)
	{
		t[x].len = r - l + 1;
		if(l == r) return ;
		build(ls,l,mid),build(rs,mid + 1,r);
	}
	void update(int x)
	{
		x += m - 1;
		t[x].l = t[x].r = t[x].f = 1;
		while(x > 1) x >>= 1,t[x] = t[ls] + t[rs];
	}
	Node query(int l,int r)
	{
		l += m - 1,r += m - 1;
		if(l == r) return t[l];
		Node x = t[l],y = t[r];
		while(l ^ r ^ 1)
		{
			if(!(l & 1)) x = x + t[l ^ 1];
			if(r & 1) y = t[r ^ 1] + y;
			l >>= 1,r >>= 1;
		}
		return x + y;
	}
} tr;
bool dif_check()
{
	for(int i = 1;i <= q;i++) if(R[i] - L[i] > 1) return true;
	return false;
}
void check()
{
	tot = 0;
	for(int i = 1;i <= n;i++) head[i] = 0;
	for(int i = 1;i <= q;i++)
		to[++tot] = i,nxt[tot] = head[M[i]],head[M[i]] = tot; 
	for(int i = 1;i < 2 * m;i++) t[i].l = t[i].r = t[i].f = 0;
	for(int i = n;i >= 1;i--)
	{
		tr.update(p[i]);
		for(int j = head[i],k;j;j = nxt[j])
		{
			k = to[j];
			if(tr.query(a[k].l,a[k].r).f >= a[k].k) L[k] = i;
			else R[k] = i;
		}
	}
}
int cyl_read()
{
	char ch = getchar();
	int x = 0;
	while(!isdigit(ch)) ch = getchar();
	while(isdigit(ch)) x = x * 10 + ch - '0',ch = getchar();
	return x;
}
void cyl_write(int x)
{
	if(x > 9) cyl_write(x / 10);
	putchar('0' + x % 10);
}
int main()
{
	freopen("query.in","r",stdin);
	freopen("query.out","w",stdout);
	n = cyl_read();
	for(int i = 1,a,b;i < n;i++)
	{
		a = cyl_read(),b = cyl_read();
		v[a].push_back(b),v[b].push_back(a);
	}
	q = cyl_read();
	for(int i = 1;i <= q;i++) a[i].l = cyl_read(),a[i].r = cyl_read(),a[i].k = cyl_read();
	dfs(1,0);
	if(!checkA())
	{
		build();
		build2();
		for(int i = 1,l,r,k,maxn;i <= q;i++)
		{
			l = a[i].l,r = a[i].r,k = a[i].k;
			maxn = 0;
			for(int j = l;j + k - 1 <= r;j++) maxn = max(maxn,dep[query(j,j + k - 1)]);
			cyl_write(maxn),putchar('\n');
		}
		return 0;
	}
	m = 1;
	while(m < n) m <<= 1;
	tr.build(1,1,m);
	for(int i = 1;i <= q;i++) L[i] = 1,R[i] = n + 1;
	for(int i = 1;i <= n;i++) p[i] = i;
	sort(p + 1,p + n + 1,cmp);
	while(dif_check())
	{
		for(int i = 1;i <= q;i++) M[i] = (L[i] + R[i]) / 2;
		check();
	}
	for(int i = 1;i <= q;i++) cyl_write(L[i]),putchar('\n');
	return 0;
}
