#include <bits/stdc++.h>
#define LL long long
#define sl(s) strlen(s)
#define endline puts("")
#define pii pair<int, int>
#define pr_q priority_queue
#define debug puts("DEBUG.")
using namespace std;
const int N = 1e5 + 10;
const int inf = ~0u >> 2;
int n,m;
struct edge
{
	int v,nxt;
}e[N];
int hd[N],cnt;
void add(int u , int v)
{
	++cnt,e[cnt].v = v;
	e[cnt].nxt = hd[u],hd[u] = cnt;
}
int d[N];
namespace sub1
{
	const int N = 5e3 + 10;
	int dep[N],top[N],dfn[N],dfn_t,f[N],siz[N],son[N];
	void dfs1(int u , int fa)
	{
		f[u] = fa;
		dep[u] = dep[fa] + 1;
		siz[u] = 1;
		for(int i = hd[u];i;i = e[i].nxt)
		{
			int v = e[i].v;
			if(v == fa)
				continue;
			dfs1(v , u);
			if(siz[v] >= siz[ son[u] ] )
				son[u] = v;
			siz[u] += siz[v];
		}
	}
	void dfs2(int u , int t)
	{
		top[u] = t;
		if(!son[u] )
			return ;
		dfs2(son[u] , t);
		for(int i = hd[u];i;i = e[i].nxt)
		{
			int v = e[i].v;
			if(v == f[u] || v == son[u] )
				continue;
			dfs2(v , v);
		}
	}
	int lca(int u , int v)
	{
		while( top[u] != top[v] )
		{
			if( dep[ top[u] ] < dep[ top[v] ] )
				swap(u , v);
			u = f[ top[u] ];
		}
		if( dep[u] > dep[v] )
			return v;
		return u;
	}
	int g[N][N];
	void main()
	{
		dfs1(1 , 0),dfs2(1 , 1);
		for(int i = 1;i <= n;i++)
		{
			g[i][i] = i;
			for(int j = i + 1;j <= n;j++)
			{
				g[i][j] = lca(g[i][j - 1] , j);
			}
		}
		while(m--)
		{
			int l,r,k;
			scanf("%d%d%d" , &l , &r , &k);
			int ans = 0;
			for(int i = l;i + k - 1 <= r;i++)
				ans = max(dep[ g[i][i + k - 1] ] , ans);
			printf("%d\n" , ans);
		}
	}
}
namespace sub2
{
	int dep[N];
	void dfs(int u , int fa)
	{
		dep[u] = dep[fa] + 1;
		for(int i = hd[u];i;i = e[i].nxt)
		{
			int v = e[i].v;
			dfs(v , u);
		}
	}
	void main()
	{
		dfs(1 , 0);
	}
}
int main()
{
//	system("fc query2.out query2.ans");
//	return 0;
	freopen("query.in" , "r" , stdin);
	freopen("query.out" , "w" , stdout);
	cin >> n;
	bool fl = 1;
	for(int i = 1,u,v;i <= n - 1;i++)
		scanf("%d%d" , &u , &v),add(u , v),add(v , u),++d[u],++d[v];
	cin >> m;
	for(int i = 1;i <= n;i++)
		fl &= d[i] <= 2;
	if(fl && d[1] == 1)
		sub2::main();
	else if(n <= 5000 && m <= 5000)
		sub1::main();
//	else sub3::main();
	return 0;
}

