#include<bits/stdc++.h>
using namespace std;
const int N=5e5+9;
int read()
{
	int ans=0;
	char c=getchar();
	while(c<'0'||c>'9')
	c=getchar();
	while(c>='0'&&c<='9')
	ans=(ans<<1)+(ans<<3)+c-'0',c=getchar();
	return ans;
}
struct dd
{
	int x,to;
}cc[2*N];
struct dd2
{
	int l,r,k;
}qj[N];
int dep[N],h[N],zg,n,m,jl[N];
deque<int>op[N];
void build(int x,int y)
{
	zg++;
	cc[zg].to=y;
	cc[zg].x=h[x];
	h[x]=zg;
}
void xz(int x)
{
	for(int i=h[x],yo;i;i=cc[i].x)
	{
		yo=cc[i].to;
		if(!dep[yo])
		{
			dep[yo]=dep[x]+1;
			xz(yo);
		}
	}
	for(int i=1;i<=m;i++)
	{
		if(qj[i].l<=x&&x<=qj[i].r)
		{
			if(qj[i].k==1)
			jl[i]=dep[x];
			qj[i].k--;
		}
	}
}
int main()
{
	freopen("query.in","r",stdin);
	freopen("query.out","w",stdout);
	n=read(),m=read();
	for(int i=1,l,r;i<=n-1;i++)
	l=read(),r=read(),build(l,r),build(r,l);
	for(int i=1,l,r,k;i<=m;i++)
	qj[i].l=read(),qj[i].r=read(),qj[i].k=read();
	dep[1]=1,xz(1);
	for(int i=1;i<=m;i++)
	cout<<jl[i]<<endl;
	return 0;
}
