#include<bits/stdc++.h>
#define pb push_back
using namespace std;
const int N=5e5+5;
int read(){
	int x=0,f=1;char ch=getchar();
	while(ch<'0'||x>'9'){
		if(ch=='-')f=-1;
		ch=getchar();
	}while(ch>='0'&&ch<='9'){
		x=(x<<3)+(x<<1)+ch-'0';
		ch=getchar();
	}return x*f;
}
void write(int x){
	if(x>9)write(x/10);
	putchar(x%10+'0');
}
int dep[N],f[N][25];
vector<int>g[N];
void dfs(int u,int fa){
	dep[u]=dep[fa]+1;
	f[u][0]=fa;
	for(auto v:g[u]){
		if(v==fa)continue;
		dfs(v,u);
	}
}
int lca(int x,int y){
	if(dep[x]<dep[y])swap(x,y);
	for(int i=20;i>=0&&dep[x]!=dep[y];i--)
		if(dep[f[x][i]]>=dep[y])x=f[x][i];
	//cout<<"jump1:"<<x<<" "<<y<<endl;
	for(int i=20;i>=0&&x!=y;i--)
		if(f[x][i]!=f[y][i])x=f[x][i],y=f[y][i];
	if(x!=y)x=f[x][0];
	return x;
}
int n,q;
struct seg{
	int e[N<<2];
	#define ls now<<1
	#define rs now<<1|1
	void build(int l,int r,int now){
		if(l==r)return e[now]=l,void();
		int mid=(l+r)>>1;
		build(l,mid,ls);
		build(mid+1,r,rs);
		e[now]=lca(e[ls],e[rs]);
	}
	int query(int l,int r,int now,int x,int y){
		if(l>=x&&r<=y)return e[now];
		int mid=(l+r)>>1,a=0,b=0;
		if(mid>=x)a=query(l,mid,ls,x,y);
		if(mid<y)b=query(mid+1,r,rs,x,y);
		if(a&&b)return lca(a,b);
		return a?a:b;
	}
}T;
int main(){
	freopen("query.in","r",stdin);
	freopen("query.out","w",stdout);
	cin>>n;
	for(int i=1,u,v;i<n;i++){
		u=read();v=read();
		g[u].pb(v);g[v].pb(u);
	}
	dfs(1,0);
	for(int i=1;i<=20;i++)
		for(int j=1;j<=n;j++)
			f[j][i]=f[f[j][i-1]][i-1];
	T.build(1,n,1);
	cin>>q;
	for(int i=1,l,r,ma,k;i<=q;i++){
		l=read();r=read();k=read();
		ma=0;
		for(int x=l,y=l+k-1;y<=r;x++,y++)
			ma=max(ma,dep[T.query(1,n,1,x,y)]);
		
		write(ma);puts("");
	}
	return 0;
}
/*
6
5 6
6 1
6 2
2 3 
2 4
5
1 2
4 5 
3 4 
5 2 
3 6 

*/

