#include <bits/stdc++.h>
#define ll long long
using namespace std;
const int M = 500005;
struct tree
{
	int d,f;
	vector <int> ch;
}t[M];
vector <int> b[M];
int nex[M],n,q,x,y,ans,l,r,k;
bool vis[M];
int main()
{
	freopen("query.in","r",stdin);
	freopen("query.out","w",stdout);
	scanf("%d",&n);
	for(int i = 1;i <= n;i++)
	{
		scanf("%d%d",&x,&y);
		b[x].push_back(y);
		b[y].push_back(x);
	}
	t[1].d = 1;
	for(int i = 1;i <= n;i++)
	{
		vis[i] = 1;
		for(int j = 0;j < b[i].size();j++)
		{
			x = b[i][j];
			if(!vis[x])
			{
				t[x].f = i,t[x].d = t[i].d + 1,t[i].ch.push_back(x),vis[x] = 1;
			}
		}
		while(!b[i].empty())
		{
			b[i].pop_back();
		}
	}
	scanf("%d",&q);
	for(int i = 1;i <= n;i++)
	{
		scanf("%d%d%d",&l,&r,&k);
		ans = 0; 
		if(k == r - l + 1)
		{
			cout << "1\n";
		}
		else if(k == 1)
		{
			ans = 1e9 + 7;
			for(int j = l;j <= r;j++)
			{
				ans = min(t[j].d,ans);
			}
			cout << ans << "\n";
		}
		else
		{
			for(int j = 0;j <= r - k + 1;j++)
			{
				x = 1e9 + 7;
				for(int m = l + j;m <= l + k - 1;m++)
				{
					x = min(t[m].d,x);
				}
				ans = min(x,ans);
			}
			cout << ans << "\n";
		}
	}
	return 0;
}
