#include<bits/stdc++.h>
#define il inline
#define ll long long
using namespace std;
#define gc() getchar()
il int rd(){
	int x=0,f=1;
	char ch=gc();
	while(!isdigit(ch)){if(ch=='-')f=-1;ch=gc();}
	while(isdigit(ch))x=(x<<1)+(x<<3)+(ch^48),ch=gc();
	return x*f;
}
/*
由于取max
所以必选长度=k的区间 
预处理LCA*[l,r]  n^2
hintB 相当于只有一个区间上个线段树
hintA 相当于取max depi i\in[] 
分块可以做到n\sqrt n 单次询问 
*/
int lca(int x,int y);
const int N=5e5+10;
struct Seg_tr{
	int w[N<<2];
	int merge(int a,int b){
		int z=0;
		if(a)z=z?lca(z,a):a;
		if(b)z=z?lca(z,b):b;
		return z;
	}
	void build(int k,int l,int r){
		if(l==r){
			w[k]=l;
			return;
		}
		int mid=(l+r)>>1;
		build(k<<1,l,mid),build(k<<1|1,mid+1,r);
		w[k]=merge(w[k<<1],w[k<<1|1]);
	}
	int query(int k,int l,int r,int L,int R){
		if(l>=L&&r<=R)return w[k];
		if(l>R||r<L)return 0;
		int mid=(l+r)>>1;
		return merge(query(k<<1,l,mid,L,R),query(k<<1|1,mid+1,r,L,R));
	}
}T;
struct QUE{
	int l,r,k;
}q[N];
int n,Q;
vector<int>e[N];
int fa[N][20],dep[N];
int lca(int x,int y){
	if(dep[x]<dep[y])swap(x,y);
	for(int i=19; ~i; --i)if(dep[fa[x][i]]>=dep[y])x=fa[x][i];
	if(x==y)return x;
	for(int i=19; ~i; --i)if(fa[x][i]!=fa[y][i])x=fa[x][i],y=fa[y][i];
	return fa[x][0];
}
void dfs(int x,int F=0){
	fa[x][0]=F;
	dep[x]=dep[F]+1;
	for(int i=1; i<20; ++i)fa[x][i]=fa[fa[x][i-1]][i-1];
	for(auto y:e[x])if(y!=F){
		dfs(y,x);
	}
}
const int M=5e3+10;
int LCA[M][M];
void BF(){
	for(int i=1; i<=n; ++i){
		LCA[i][i]=i;
		for(int j=i+1; j<=n; ++j){
			LCA[i][j]=lca(LCA[i][j-1],j);
		}
	}
	for(int l,r,k,t=1; t<=Q; ++t){
		l=q[t].l,r=q[t].r,k=q[t].k;
		int ans=0;
		for(int i=l; i+k-1<=r; ++i)ans=max(ans,dep[LCA[i][i+k-1]]);
		printf("%d\n",ans);
	}
}
const int NM=1e5+10;

void HintA(){
	
}
void HintB(){
	T.build(1,1,n);
	for(int l,r,k,t=1; t<=Q; ++t){
		l=q[t].l,r=q[t].r,k=q[t].k;
		printf("%d\n",dep[T.query(1,1,n,l,r)]);
	}
}
int d[N];
void Main(){
	n=rd();
	for(int u,v,i=1; i<n; ++i){
		u=rd(),v=rd();
		e[u].push_back(v);
		e[v].push_back(u);
		++d[u],++d[v];
	}
	dfs(1);
	Q=rd();
	for(int i=1; i<=Q; ++i){
		q[i].l=rd(),q[i].r=rd(),q[i].k=rd();
	}
	if(n<=5e3&&Q<=5e3){
		BF();return;
	}
	bool fl;
	fl=1;
	for(int i=1; i<=Q; ++i)fl&=(q[i].k==q[i].r-q[i].l+1);
	if(fl){HintB();return;}
	BF();
}
int main(){
	freopen("query.in","r",stdin);
	freopen("query.out","w",stdout);
	int T=1;
	while(T--)Main();

	return 0;
}

