#include<bits/stdc++.h>
#define max(a,b) (a>b?a:b)
#define min(a,b) (a<b?a:b)
using namespace std;
const int maxn=1e5+7;
inline int read()
{
	int x=0;char ch=getchar();
	while(ch<='9'&&ch>='0') x=(x<<3)+(x<<1)+(ch^48),ch=getchar();
	return x;
}
int fa[maxn],siz[maxn],son[maxn],top[maxn],dep[maxn];
vector<int> G[maxn];
void dfs1(int x)
{
	siz[x]=1,dep[x]=dep[fa[x]]+1;int l=0;
	for(int i:G[x])
	{
		if(i==fa[x]) continue;
		fa[i]=x;dfs1(i);
		siz[x]+=siz[i];
		if(siz[i]>l) son[x]=i,l=siz[i];
	}
}
void dfs2(int x,int y)
{
	if(x==0) return;
	top[x]=y;dfs2(son[x],y);
	for(int i:G[x])
	{
		if(i==fa[x]||i==son[x]) continue; 
		dfs2(i,i);
	}
}
int find(int x,int y)
{
	while(top[x]!=top[y])
	{
		if(dep[top[x]]<dep[top[y]]) swap(x,y);
		x=fa[top[x]];
	}
	if(dep[top[x]]<dep[top[y]]) swap(x,y);
	return y;
}
int ask(int l,int r)
{
	int u=find(l,l+1);
	for(int i=l+1;i<=r;i++) u=find(u,i);
	return u;
}
int main()
{
	int n=read();
	for(int i=1;i<n;i++)
	{
		int x=read(),y=read();
		G[x].push_back(y);
		G[y].push_back(x);
	} 
	fa[1]=1;
	dfs1(1);dfs2(1,1);
	int q=read();
	while(q--)
	{
		int l=read(),r=read(),k=read(),p=0;
		for(int i=l+k-1;i<=r;i++) 
		{
			int x=find(i-k+1,i);
			if(dep[x]>p) p=dep[x];
		}
		cout<<p<<"\n";
	}
}
