#include<bits/stdc++.h>
#define ll long long
#define ls u<<1
#define rs u<<1|1
#define up(i,a,b) for(int i=a;i<=b;i++)
#define dn(i,a,b) for(int i=a;i>=b;i--)
using namespace std;
const int N=5e5+10;
int n,q,dfn[N],dep[N],cnt,s[25][N],mi[25][N],ma[25][N],inv[N];
vector<int> G[N];
void dfs(int u,int fa)
{
	dfn[u]=++cnt;dep[u]=dep[fa]+1;
	inv[cnt]=u;
	s[0][cnt]=u;
	mi[0][u]=ma[0][u]=cnt;
	for(auto v:G[u])
	{
		if(v==fa)continue;
		dfs(v,u);
	}
}
int get(int x,int y)
{
	return dep[x]<dep[y]?x:y;
}
int main()
{
	freopen("query.in","r",stdin);
	freopen("query.out","w",stdout);
	ios::sync_with_stdio(0);
	cin.tie(0);cout.tie(0);
	cin>>n;	
	up(i,1,n-1)
	{
		int u,v;
		cin>>u>>v;
		G[u].push_back(v);
		G[v].push_back(u);
	}
	dfs(1,0);
	up(i,1,20)
	up(j,1,n-(1<<i)+1)
	{
		s[i][j]=get(s[i-1][j+(1<<(i-1))],s[i-1][j]);
		ma[i][j]=max(ma[i-1][j+(1<<(i-1))],ma[i-1][j]);
		mi[i][j]=min(mi[i-1][j+(1<<(i-1))],mi[i-1][j]);
	}	
	cin>>q;
	while(q--)
	{
		int l,r,k;
		cin>>l>>r>>k;
		if(k==r-l+1)
		{
			int t=__lg(r-l+1);
			int x=max(ma[t][l],ma[t][r-(1<<t)+1]);
			int y=min(mi[t][l],mi[t][r-(1<<t)+1]);
			t=__lg(x-y+1);
			int ykj=get(s[t][y],s[t][x-(1<<t)+1]);
			cout<<dep[ykj]-1<<'\n';
		}
		else
		{
			if(n<=5000)
			{
				int ans=0;
				up(L,l,r-k+1)
				{
					int R=L+k-1;
					int t=__lg(R-L+1);
					int x=max(ma[t][L],ma[t][R-(1<<t)+1]);
					int y=min(mi[t][L],mi[t][R-(1<<t)+1]);
					t=__lg(x-y+1);
					int ykj=get(s[t][y],s[t][x-(1<<t)+1]);
					if(dep[ykj]>dep[ans])ans=ykj;
				}
				cout<<dep[ans]-1<<'\n';
			}
			else cout<<1<<'\n';
		}
	}
	return 0;
}
