#include<bits/stdc++.h>
using namespace std;

const int R=30+5;
const int N=1e6+10;

int n,cnt,m;
int st[R][N];
int head[N],nxt[N<<1],to[N<<1];
int tp[N],fa[N],son[N],siz[N],dep[N];

void link(int x,int y){
    nxt[++cnt]=head[x],head[x]=cnt,to[cnt]=y;
}

void DFS(int x){
    siz[x]=1,dep[x]=dep[fa[x]]+1;
    for(int i=head[x];i;i=nxt[i]){
        if(to[i]==fa[x]) continue;
        fa[to[i]]=x,DFS(to[i]),siz[x]+=siz[to[i]];
        if(siz[to[i]]>siz[son[x]]) son[x]=to[i];
    }
}

void FST(int x){
    if(son[fa[x]]==x) tp[x]=tp[fa[x]];
    else tp[x]=x;
    if(son[x]) FST(son[x]);
    for(int i=head[x];i;i=nxt[i]){
        if(to[i]==fa[x]||to[i]==son[x]) continue;
        FST(to[i]);
    }
}

int lca(int x,int y){
    while(tp[x]!=tp[y]){
        if(dep[tp[x]]<dep[tp[y]]) swap(x,y);
        x=fa[tp[x]];
    }
    if(dep[x]>dep[y]) swap(x,y);
    return x;
}

struct SGT{
    int tr[N<<3];
    void build(int num,int l,int r){
        if(l==r) tr[num]=l;
        int mid=(l+r)>>1;
        build(num<<1,l,mid),build(num<<1|1,mid+1,r);
        tr[num]=lca(tr[num<<1],tr[num<<1|1]);
    }
    int query(int num,int l,int r,int lf,int rt){
        if(lf<=l&&r<=rt) return tr[num];
        int mid=(l+r)>>1;int ans=1;
        if(lf<=mid) ans=lca(ans,query(num<<1,l,mid,lf,rt));
        if(mid<rt) ans=lca(ans,query(num<<1|1,mid+,r,lf,rt));
        return ans;
    }
}T;

int main(){
    freopen("query.in","r",stdin);
    freopen("query.out","w",stdout);
    n=read(),m=read();
    for(int i=1;i<n;++i){
        int x=read(),y=read();
        link(x,y),link(y,x);
    }
    DFS(1),FST(1),T.build(1,1,n);
    for(int i=1;i<=m;++i){
        int l=read(),r=read(),k=read();
        int ans=0;
        for(int j=l;j<=r-k+1;++j)
            ans=max(ans,dep[T.query(j,j+k-1)]);
        printf("%d\n",ans);
    }
    return 0;
}