#include<cstdio>
using namespace std;
#define fo(i,a,b) for(int i=a;i<=b;++i)
#define fe(i,a,b) for(int i=a;i>=b;--i)
#define ll long long
#define cl u<<1
#define cr u<<1|1
const int N=5e5+5,E=20;
int n,Q,head[N],nxt[N<<1],to[N<<1],cnt,d[5005][5005],fa[N],pa[N][E+5],dep[N],t[N<<2];
bool fl[5005][5005];
void ins(int u,int v){nxt[++cnt]=head[u],head[u]=cnt,to[cnt]=v;}
void dfs(int u)
{
	fo(j,1,E) pa[u][j]=pa[pa[u][j-1]][j-1];
	for(int i=head[u];i;i=nxt[i])
	{
		int v=to[i];
		if(v!=fa[u]) fa[v]=u,pa[v][0]=u,dep[v]=dep[u]+1,dfs(v);
	}
}
void swap(int &o,int &p){int z=o;o=p,p=z;}
int lca(int u,int v)
{
	if(dep[u]>dep[v]) swap(u,v);
	fe(j,E,0) if(dep[pa[v][j]]>=dep[u]) v=pa[v][j];
	if(u==v) return u;
	fe(j,E,0) if(pa[u][j]!=pa[v][j]) u=pa[u][j],v=pa[v][j];
	return pa[u][0];
}
void build(int u,int l,int r)
{
	if(l>=r)
	{
		t[u]=l;
		return ;
	}
	int mid=(l+r)>>1;
	build(cl,l,mid),build(cr,mid+1,r),t[u]=lca(t[cl],t[cr]);
}
int ask(int u,int l,int r,int S,int T)
{
	if(S<=l&&r<=T) return t[u];
	int mid=(l+r)>>1;
	if(S<=mid)
		if(mid<T) return lca(ask(cl,l,mid,S,T),ask(cr,mid+1,r,S,T));
		else return ask(cl,l,mid,S,T);
	else return ask(cr,mid+1,r,S,T);
}
inline int max(int o,int p){return o>p?o:p;}
int main()
{
	freopen("query.in","r",stdin);
	freopen("query.out","w",stdout);
	scanf("%d",&n);
	fo(i,1,n-1)
	{
		int u,v;
		scanf("%d%d",&u,&v),ins(u,v),ins(v,u);
	}
	dep[1]=1,dfs(1);
	if(n<=5000)
	{
		fo(i,1,n)
		{
			int u=i;
			while(u) fl[i][u]=1,u=fa[u];
		}
		fo(i,1,n)
		{
			d[i][i]=i;
			int u=i;
			fo(j,i+1,n)
			{
				while(!fl[j][u]) u=fa[u];
				d[i][j]=u;
			}
		}
		scanf("%d",&Q);
		while(Q--)
		{
			int l,r,k;
			scanf("%d%d%d",&l,&r,&k);
			int ans=0;
			fo(i,l,r-k+1) ans=max(ans,dep[d[i][i+k-1]]);
			printf("%d\n",ans);
		}
		return 0;
	}
	build(1,1,n);
	scanf("%d",&Q);
	while(Q--)
	{
		int l,r,k;
		scanf("%d%d%d",&l,&r,&k);
		printf("%d\n",dep[ask(1,1,n,l,r)]);
	}
	return 0;
}
/*
10
1 2
1 3
1 4
2 5
3 6
4 7
4 8
1 9
2 10
5
7 8 2
1 4 4
3 3 1
4 7 3
2 7 6
*/
