#include <iostream>
#include <cstring>
#include <algorithm>
#include <queue>

using namespace std;

const int N=500010,M=2*N,MXT=21;
int n;
int h[N],e[M],ne[M],idx;
int depth[N],fa[N][MXT];
struct node
{
	int l,r;
	int dat;
} tr[N*4];

void add(int u,int v)
{
	e[idx]=v;
	ne[idx]=h[u],h[u]=idx++;
}

void init()
{
	memset(depth,0x3f,sizeof(depth));
	queue<int> q;
	q.push(1);
	depth[1]=1,depth[0]=0;
	while (!q.empty())
	{
		int u=q.front();
		q.pop();
		for (int i=h[u];i!=-1;i=ne[i])
		{
			int v=e[i];
			if (depth[v]>depth[u]+1)
			{
				depth[v]=depth[u]+1;
				q.push(v);
				
				fa[v][0]=u;
				for (int t=1;t<=20;t++) fa[v][t]=fa[fa[v][t-1]][t-1];
			}
		}
	}
}

int lca(int u,int v)
{
	if (!u) return v;
	if (depth[u]<depth[v]) swap(u,v);
	for (int t=20;t>=0;t--)
	{
		if (depth[fa[u][t]]>=depth[v])
		{
			u=fa[u][t];
		}
	}
	if (u==v) return u;
	for (int t=20;t>=0;t--)
	{
		if (fa[u][t]!=fa[v][t])
		{
			u=fa[u][t];
			v=fa[v][t];
		}
	}
	return fa[u][0];
}

void pushup(int u)
{
	tr[u].dat=lca(tr[u*2].dat,tr[u*2+1].dat);
}

void build(int u,int l,int r)
{
	tr[u].l=l,tr[u].r=r;
	if (l==r)
	{
		tr[u].dat=l;
		return;
	}
	int mid=l+(r-l)/2;
	build(u*2,l,mid);
	build(u*2+1,mid+1,r);
	pushup(u);
}

int query(int u,int l,int r)
{
	if (l<=tr[u].l && tr[u].r<=r) return tr[u].dat;
	int mid=tr[u].l+(tr[u].r-tr[u].l)/2;
	int res=0;
	if (l<=mid) res=lca(res,query(u*2,l,r));
	if (r>mid) res=lca(res,query(u*2+1,l,r));
	return res;
}

int main()
{
	freopen("query.in","r",stdin);
	freopen("query.out","w",stdout);
	
	cin >> n;
	memset(h,-1,sizeof(h));
	for (int i=1;i<=n-1;i++)
	{
		int u,v;
		cin >> u >> v;
		add(u,v);
		add(v,u);
	}
	
	init();
	build(1,1,n);
	
	int q;
	cin >> q;
	while (q--)
	{
		int l,r,k;
		cin >> l >> r >> k;
		
		int mxd=0;
		for (int L=l;L+k-1<=r;L++)
		{
			for (int R=L+k-1;R<=r;R++)
			{
				int d=depth[query(1,L,R)];
				mxd=max(mxd,d);
			}
		}
		cout << mxd << "\n";
	}
	
	return 0;
}
