#include<bits/stdc++.h>
#define ll int
#define il inline
#define vd void
#define bl bool
#define fr(x) freopen(#x".in","r",stdin);freopen(#x".out","w",stdout)
using namespace std;
const ll N=5e5+4;
ll n,q,i,j,l,r,k,x,y,cnt,mx,ans;
ll a[N],h[N],f[N],d[N],s[N],wc[N],t[N];
struct zjy{ll to,next;}e[N<<1];
il ll R()
{
    ll n=0,f=1;
    char c=getchar();
    for(;(c<'0'||c>'9')&&c!='-';c=getchar());
    if(c=='-') f=-1,c=getchar();
    for(;c>='0'&&c<='9';c=getchar()) n=(n<<1)+(n<<3)+c-'0';
    return n*f;
}
il vd W(ll x)
{
    if(x<0) putchar('-'),x=-x;
    if(x>9) W(x/10);
    putchar(x%10+'0');
}
il vd add(ll x,ll y){e[++cnt]={y,h[x]};h[x]=cnt;}
il vd sv(ll x)
{
    ll i,y;
    s[x]=1;
    for(i=h[x];i;i=e[i].next)
    {
        if((y=e[i].to)!=f[x])
        {
            f[y]=x;
            d[y]=d[x]+1;
            sv(y);
            s[x]+=s[y];
            s[wc[x]]<s[y]&&(wc[x]=y);
        }
    }
}
il vd sv2(ll x,ll tp)
{
    ll i,y;
    t[x]=tp;
    if(wc[x]) sv2(wc[x],tp);
    for(i=h[x];i;i=e[i].next) (y=e[i].to)!=f[x]&&y!=wc[x]&&(sv2(y,y),0);
}
il ll lca(ll x,ll y)
{
    while(t[x]!=t[y])
    {
        d[t[x]]<d[t[y]]&&(x^=y^=x^=y);
        x=f[t[x]];
    }
    return d[x]<d[y]?x:y;
}
signed main()
{
    fr(query);
    for(n=R(),i=1;i<n;++i) x=R(),y=R(),add(x,y),add(y,x);
    d[1]=1,sv(1),sv2(1,1);
    for(q=R();q--;)
    {
        for(l=R(),r=R(),k=R(),mx=0,i=l,x=r-k+1;i<=x;++i)
        {
            for(ans=i,y=min(i+k,r+1),j=i+1;j<y;++j) ans=lca(ans,j);
            for(mx=max(mx,d[ans]);j<=r;++j)
            {
                ans=lca(ans,j);
                mx=max(mx,d[ans]);
            }
        }
        W(mx);
        putchar('\n');
    }
    return 0;
}