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

int read()
{
	int ret = 0;char c = getchar();
	while(c < '0' || c > '9')c = getchar();
	while(c >= '0' && c <= '9')ret = ret*10+c-48,c = getchar();
	return ret;
}
void write(int x)
{
	if(x/10)write(x/10);
	putchar(x%10+48);
}

int n,q;

struct edge
{
	int v,nex;
}e[2*N];
int tot,head[N];
void add(int u,int v)
{
	e[++tot].v = v,e[tot].nex = head[u],head[u] = tot;
}

int lg[N],dis[N],fa[N][30];
void init()
{
	for(int i = 1;i <= n;i++)lg[i] = lg[i-1] + (1<<lg[i-1] == i);
}
void dfs(int las,int u)
{
	dis[u] = dis[las] + 1;
	fa[u][0] = las;
	for(int i = 1;i <= lg[dis[u]];i++)
		fa[u][i] = fa[fa[u][i-1]][i-1];
	for(int i = head[u];i;i = e[i].nex)
	{
		int v = e[i].v;
		if(v == las)continue;
		dfs(u,v);
	}
}
int lca(int u,int v)
{
	if(dis[u] < dis[v])swap(u,v);
	while(dis[u] > dis[v])u = fa[u][lg[dis[u]-dis[v]]-1];
	if(u == v)return u;
	for(int i = lg[dis[u]]-1;i+1;i--)
		if(fa[u][i] != fa[v][i])
			u = fa[u][i],v = fa[v][i];
	return fa[u][0];
}

struct node
{
	int l,r,v;
}t[4*N];
void build(int u,int l,int r)
{
	t[u].l = l,t[u].r = r;
	if(l == r)
	{
		t[u].v = l;
		return;
	}
	int mid = l+r>>1;
	build(2*u,l,mid);
	build(2*u+1,mid+1,r);
	t[u].v = lca(t[2*u].v,t[2*u+1].v);
}
int ask(int u,int l,int r)
{
	if(l <= t[u].l && t[u].r <= r)return t[u].v;
	int mid = t[u].l+t[u].r>>1;
	if(l <= mid && mid < r)return lca(ask(2*u,l,r),ask(2*u+1,l,r));
	if(l <= mid)return ask(2*u,l,r);
	if(mid < r)return ask(2*u+1,l,r);
}

int main()
{
	freopen("query.in","r",stdin);
	freopen("query.out","w",stdout);
	n = read();
	init();
	for(int i = 1;i < n;i++)
	{
		int u = read(),v = read();
		add(u,v),add(v,u);
	}
	dfs(0,1);
	build(1,1,n);
	q = read();
	while(q--)
	{
		int l = read(),r = read(),k = read();
		int maxx = 0;
		for(int i = l,j = l+k-1;j <= r;i++,j++)
			maxx = max(maxx,i == j?dis[i]:dis[ask(1,i,j)]);
		write(maxx),putchar(10);
	}
	return 0; 
}
