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

const int N = 1e6 + 10;
const int M = 2e6 + 10;
int head[N],nex[M],to[M],tot;
void ins(int u,int v)
{
	++tot;
	nex[tot] = head[u];
	head[u] = tot;
	to[tot] = v;
}
int dep[N],fd[N];
bool flagA = true;
void dfs(int fa,int x,int d)
{
	dep[x] = d;
	if(!fd[d])fd[d] = x;
	else flagA = false;
	for(int i = head[x];i;i = nex[i])
	{
		int v = to[i];
		if(v==fa)continue;
		dfs(x,v,d+1);
	}
}
int a[N];

int main()
{
	freopen("query.in","r",stdin);
	freopen("query.out","w",stdout);
	
	int n;
	scanf("%d",&n);
	for(int i = 1;i<n;i++)
	{
		int x,y;
		scanf("%d%d",&x,&y);
		ins(x,y);
		ins(y,x);
	}
	dfs(0,1,1);
	if(flagA)
	{
		
		int q;
		scanf("%d",&q);
		while(q--)
		{
			int l,r,k;
			scanf("%d%d%d",&l,&r,&k);
			for(int i = l;i<=r;i++)
				a[i] = dep[i];
			sort(a+l,a+r+1);
			cout<<a[r-k+1]<<endl;
		}
	}
	
	fclose(stdin);
	fclose(stdout);
	return 0;
 } 
