#include<bits/stdc++.h>
using namespace std;
#define int long long
#define f(i,j,k) for(int i=j;i<=k;++i)
#define g(i,j,k) for(int i=j;i>=k;--i)
int n,m,s,l;
struct IO{const static int N=1<<20,u=3; char a[N];int l,r;char gc(){if(l==r)fread(a,1,u,stdin),l=0,r=u;return a[l++];}}IO;
inline int read(){
	int x=0;char ch=IO.gc();
	for(;'0'>ch||ch>'9';ch=IO.gc());
	for(;'0'<=ch&&ch<='9';ch=IO.gc())x=(x<<3)+(x<<1)+(ch^48);
	return x; 
}
const int N=1e6;
#undef int
struct op{int l,r,v,w;};
inline op operator+(op a,op b){return{a.w==a.v?a.v+b.l:a.l,b.w==b.v?a.r+b.v:b.r,a.v+b.v,max({a.w,b.w,a.r+b.l})};}
struct Kazemaru{
	const static int M=1.01e7;
	struct xds{int ls,rs;op c;}a[M];int t;
	#define M (L+R)/2
	void put(int&id,int x,int L,int R){
		a[++t]=a[id];id=t;
		if(L==R)return a[id].c={1,1,1,1},void();
		x>M?put(a[id].rs,x,M+1,R):put(a[id].ls,x,L,M);
		a[id].c=a[a[id].ls].c+a[a[id].rs].c;
	}
	op ask(int id,int l,int r,int L,int R){
		if(r<L||R<l)return{};
		if(!id||(l<=L&&R<=r))return a[id].c;
		return ask(a[id].ls,l,r,L,M)+ask(a[id].rs,l,r,M+1,R);
	}
}T;int rt[N];
#define int long long
struct ST{
	const static int N=1e6+9,k=20;
	int f[N][22],o[N],p[N];
	inline void init(int&n,int*a){
		f(i,1,n)f[i][0]=a[i];
		f(i,0,k)o[i]=1<<i;
		f(i,1,n)p[i]=__lg(i);
		f(t,1,k)f(i,1,n)if(i+o[t]-1<=n)f[i][t]=min(f[i][t-1],f[i+o[t-1]][t-1]);
	}
	inline int ask(int l,int r){if(l>r)swap(l,r);int t=p[r-l+1];return min(f[l][t],f[r-o[t]+1][t]);}
}A;
int c[N],d[N],L[N],R[N],x,y,r,k;
vector<int>p[N],q[N];
void dfs(int x,int fa){
	c[L[x]=++l]=d[x]=d[fa]+1;
	for(int y:q[x])if(y!=fa)dfs(y,x);
	c[R[x]=++l]=d[fa];
}
inline int lca(int x,int y){return A.ask(L[x],L[y]);}
signed main(){
	freopen("query.in","r",stdin);
	freopen("query.out","w",stdout);
	n=read();
	f(i,2,n){
		x=read();y=read();
		q[x].push_back(y);
		q[y].push_back(x);
	}
	dfs(1,0);A.init(l,c);
	f(i,2,n)p[lca(i-1,i)].push_back(i);
	T.a[0]={0,0,{0,0,1,0}};
	g(i,n,1){
		rt[i]=rt[i+1];
		for(int x:p[i])T.put(rt[i],x,1,n);
	}
	f(i,1,n)d[i]=-d[i];A.init(n,d);
	m=read();
	f(_,1,m){
		l=read();r=read();k=read();
		if(k<2){
			printf("%lld\n",-A.ask(l,r));
		}else{
			int le=1,ri=n,mid;++l;--k;
			for(;le<ri;T.ask(rt[mid],l,r,1,n).w>=k?le=mid:ri=mid-1)mid=(le+ri+1)/2;
			printf("%lld\n",ri);
		}
	}
	return 0;
}
