#include<iostream>
#include<vector>
#include<cmath>
#include<algorithm>
#include<unordered_map>
using namespace std;
const int MAXN=5e5+100;
vector<int> edge[MAXN];
bool vis[MAXN];
int fa[32][MAXN],dep[MAXN];
int n,q;
bool flag=true;

inline int lc(int x){return x<<1;}
inline int rc(int x){return x<<1|1;}
struct node
{
	int l,r,min;
	int lca;	
} tree[MAXN*4];
void pull_upA(int p)
{
	tree[p].min=min(tree[lc(p)].min,tree[rc(p)].min);
}
int lca(int a,int b)
{
	if(dep[a]>dep[b]) swap(a,b);
	for(int i=31;i>=0;i--)
		if(dep[fa[i][b]]>=dep[a])
			b=fa[i][b];
	for(int i=31;i>=0;i--)
		if(fa[i][b]!=fa[i][a])
			b=fa[i][b],a=fa[i][a];
	return b;
}
void pull_upB(int p)
{	
	tree[p].min=dep[lca(tree[lc(p)].lca,tree[rc(p)].lca)];
}
void build_tree(int l,int r,int p)
{
	if(r<=l)
	{
		tree[p].l=tree[p].r=l;
		tree[p].min=dep[l];
		tree[p].lca=l;
		return;
	}
	tree[p].l=l;
	tree[p].r=r;
	int mid=(r+l)/2;
	build_tree(l,mid,lc(p));
	build_tree(mid+1,r,rc(p));
	if(flag)
		pull_upA(p);
	else
		pull_upB(p);
}
int ask(int l,int r,int p)
{
	if(tree[p].r<l||tree[p].l>r)
		return 0x7f7f7f7f; 
	if(l<=tree[p].l&&r>=tree[p].r)
		return tree[p].min;
	int mid=(tree[p].l+tree[p].r)/2;
	int minn=0x7f7f7f7f;
	if(l<=mid)
		minn=min(minn,ask(l,r,lc(p)));
	if(mid<=r)
		minn=min(minn,ask(l,r,rc(p)));
	return minn;
}
unordered_map<int,int> m;
void dfs(int r,int d,int f)
{
	if(vis[r]) return;
	vis[r]=true;
	dep[r]=d;
	fa[0][r]=f;
	for(int c:edge[r])
		dfs(c,d+1,r);
}
int main()
{
	FILE *fp;
	fp=freopen("query.in","r",stdin);
	fp=freopen("query.out","w",stdout);
	cin>>n;
	for(int i=1;i<n;i++)
	{
		int u,v,tmp;
		tmp=scanf("%d%d",&u,&v);
		edge[u].push_back(v);
		edge[v].push_back(u);
	}
	dfs(1,0,0);
	for(int i=1;i<32;i++)
		for(int j=1;j<=n;j++)
			fa[i][j]=fa[i-1][fa[i-1][j]];
	for(int j=1;j<=n;j++)
	{
		m[dep[j]]++;
		if(m[dep[j]]>1)
		{
			flag=false;
			break;
		} 
	}
	build_tree(1,n,1); 
	cin>>q;
	while(q--)
	{
		int l,r,k,tmp;
		tmp=scanf("%d%d%d",&l,&r,&k);
		if(flag||k==(r-l+1)) 
			printf("%d\n",ask(l,r,1)+1);
		else
		{
			int maxn=-1;
			for(int i=(r-l+1);i>=k;i--)
				for(int j=1;j+i<=n;j++)
					maxn=max(maxn,ask(j,j+i,1));
			printf("%d\n",maxn+1);
		}
	}
	fclose(stdin);
	fclose(stdout);
	return 0;
}
