#include<bits/stdc++.h>
using namespace std;
const int MAXN=5e5+10;
struct Node{
	int dep;
	vector<int>son;
	int f[30];
}tree[MAXN];
int n;
int u,v;
int q;
int ans;
int l,r,k;
int now;
void init(int now,int fa)
{
	tree[now].dep=tree[fa].dep+1;
	for(int i=1;i<=25;i++)
		tree[now].f[i]=tree[tree[now].f[i-1]].f[i-1];
	for(auto to:tree[now].son)
	{
		if(to==fa)continue;
		tree[to].f[0]=now;
		init(to,now);
	}
}
int LCA(int x,int y)
{
	if(tree[x].dep<tree[y].dep)swap(x,y);
	for(int i=25;i>=0;i--)
	{
		if(tree[tree[x].f[i]].dep>=tree[y].dep)
			x=tree[x].f[i];
		if(x==y)return x;
	}
	for(int i=25;i>=0;i--)
	{
		if(tree[x].f[i]!=tree[y].f[i])
		{
			x=tree[x].f[i];
			y=tree[y].f[i];
		}
	}
	return tree[x].f[0];
}
int tree2[MAXN*4];
int ls(int p){return p<<1;}
int rs(int p){return p<<1|1;}
void push_up(int p)
{
	tree2[p]=LCA(tree2[ls(p)],tree2[rs(p)]);
}
void build(int p,int pl,int pr)
{
	if(pl==pr)
	{
		tree2[p]=pl;
//		cout<<"build()|"<<pl<<"->"<<pr<<":"<<tree2[p]<<endl;
		return ;
	}
	int mid=(pl+pr)>>1;
	build(ls(p),pl,mid);
	build(rs(p),mid+1,pr);
	push_up(p);
//	cout<<"build()|"<<pl<<"->"<<pr<<":"<<tree2[p]<<endl;
}
void query(int p,int pl,int pr,int l,int r)
{
	if(l<=pl&&pr<=r)
	{
		now=LCA(now,tree2[p]);
		return ;
	}
	int mid=(pl+pr)>>1;
	if(mid>=l)query(ls(p),pl,mid,l,r);
	if(mid<r)query(rs(p),mid+1,pr,l,r);
}
int main()
{
	freopen("query3.in","r",stdin);
	freopen("query3.out","w",stdout);
	scanf("%d",&n);
	for(int i=1;i<n;i++)
	{
		scanf("%d%d",&u,&v);
		tree[u].son.push_back(v);
		tree[v].son.push_back(u);
	}
	init(1,0);
	build(1,1,n);
	scanf("%d",&q);
	for(int i=1;i<=q;i++)
	{
		scanf("%d%d%d",&l,&r,&k);
		ans=0;
		for(int j=l;j+k-1<=r;j++)
		{
//			cout<<j<<"->"<<j+k-1<<":"<<query(1,1,n,j,j+k-1)<<endl;
			now=j;
			query(1,1,n,j,j+k-1);
			ans=max(ans,tree[now].dep);
		}
		printf("%d\n",ans);
	}
	fclose(stdin);
	fclose(stdout);
	return 0;
 } 
 /*
6
5 6
6 1
6 2
2 3
2 4
3
2 5 2
1 4 1
1 6 3

 */ 
