#include<bits/stdc++.h>
using namespace std;
namespace IO{
	template<class T> inline void read(T &x){
		char ch=getchar(),fushu=0; x=0;
		while(ch<'0'||ch>'9'){
			if(ch=='-')fushu=1;
			ch=getchar();
		}
		while(ch>='0'&&ch<='9')x=x*10+(ch^48),ch=getchar();
		if(fushu)x=-x;
	}
	char p[205];
	template<class T> inline void write(T x){
		if(x<0)putchar('-'),x=-x;
		if(!x)putchar('0');
		int t=0;
		while(x)p[++t]=(x%10)^48,x/=10;
		while(t)putchar(p[t--]);
	}
}
using IO::read;
using IO::write;
#define ll long long
#define ull unsigned long long
#define ld long double
#define it128 __int128
#define fo(i,l,r) for(int i=(l);i<=(r);++i)
#define fd(i,r,l) for(int i=(r);i>=(l);--i)
#define fu(i,l,r) for(int i=(l);i<(r);++i)
int n,Q;
const int N=5e5+5;
vector<int> g[N];
int bg[N],ed[N];
int mn[19][N],mx[19][N];
int dep[N],d[N*2],tot;
int Mn[20][N*2];
void dfs(int x,int y){
	dep[x]=dep[y]+1;
	d[++tot]=dep[x];
	ed[x]=bg[x]=tot;
	for(int v:g[x]){
		if(v==y)continue;
		dfs(v,x);
		d[++tot]=dep[x];
		ed[x]=tot;
	}
}
int get_min(int l,int r){
	int len=r-l+1;
	return min(mn[__lg(len)][l],mn[__lg(len)][r-(1<<__lg(len))+1]);
}
int get_max(int l,int r){
	int len=r-l+1;
	return max(mx[__lg(len)][l],mx[__lg(len)][r-(1<<__lg(len))+1]);
}
int query(int l,int r){
	int len=r-l+1;
	return min(Mn[__lg(len)][l],Mn[__lg(len)][r-(1<<__lg(len))+1]);
}
signed main(){
	freopen("query.in","r",stdin);
	freopen("query.out","w",stdout);
	read(n);
	fo(i,1,n-1){
		int u,v;
		read(u),read(v);
		g[u].push_back(v);
		g[v].push_back(u);
	}
	dfs(1,0);
	fo(i,1,n)mn[0][i]=bg[i],mx[0][i]=ed[i];
	fo(i,1,__lg(n)){
		fo(j,1,n-(1<<i)+1){
			mn[i][j]=min(mn[i-1][j],mn[i-1][j+(1<<i-1)]);
			mx[i][j]=max(mx[i-1][j],mx[i-1][j+(1<<i-1)]);
		}
	}
	fo(i,1,2*n-1)Mn[0][i]=d[i];
	fo(i,1,__lg(2*n-1)){
		fo(j,1,2*n-(1<<i)){
			Mn[i][j]=min(Mn[i-1][j],Mn[i-1][j+(1<<i-1)]);
		}
	}
	read(Q);
	while(Q--){
		int l,r,k;
		read(l),read(r),read(k);
		int ans=0;
		fo(i,l,r-k+1){
			int b=get_min(i,i+k-1),e=get_max(i,i+k-1);
			ans=max(ans,query(b,e));
		}
		write(ans),putchar('\n');
	}
	return 0;
}

