#include<bits/stdc++.h>
#define M 500010
#define N 25
using namespace std;
int n,x,y,k,q,d[M],l[M][N],f[M][N],s,lg[M];vector<int> v[M];
void dfs(int x,int l)
{
	d[x]=d[l]+1;
	f[x][0]=l;
	for(register int i=1;i<=19;i++)
		f[x][i]=f[f[x][i-1]][i-1];
	for(auto y:v[x])if(y!=l)dfs(y,x);
}
int lca(int x,int y)
{
	if(d[x]<d[y])swap(x,y);
	for(register int i=19;i>=0;i--)
		if(d[f[x][i]]>=d[y])x=f[x][i];
	if(x==y)return x;
	for(register int i=19;i>=0;i--)
		if(f[x][i]!=f[y][i])x=f[x][i],y=f[y][i];
	return f[x][0];
}
int pd(int x,int y,int k)
{
	int w=lg[k];
	return lca(l[x][w],l[y-(1<<w)+1][w]);
}
int main()
{
	freopen("query.in","r",stdin);
	freopen("query.out","w",stdout);
	std::ios::sync_with_stdio(false),cin.tie(0),cout.tie(0);
	cin>>n;
	for(register int i=2;i<=n;i++)lg[i]=lg[i>>1]+1;
	for(register int i=1;i<n;i++)
	{
		cin>>x>>y;
		v[x].push_back(y);
		v[y].push_back(x);
	}
	dfs(1,0);
	for(register int i=1;i<=n;i++)l[i][0]=i;
	for(register int j=1;j<=19;j++)
		for(register int i=1;i+(1<<j)-1<=n;i++)
			l[i][j]=lca(l[i][j-1],l[i+(1<<(j-1))][j-1]);
	cin>>q;
	while(q--)
	{
		cin>>x>>y>>k,s=1;
		for(register int i=x,j=x+k-1;j<=y;i++,j++)
			s=max(s,d[pd(i,j,k)]);
		cout<<s<<'\n';
	}
	return 0;
}
