#include<bits/stdc++.h>
#define rg register int
#define fo(i,l,r) for(rg i=(l);i<=(r);i++)
#define dfo(i,r,l) for(rg i=(r);i>=(l);i--)
#define fe(i,x) for(rg i=hd[x];i;i=nex[i])
#define frein freopen("in.txt","r",stdin)
#define freout freopen("out.txt","w",stdout)
#define fre(p) freopen(#p".in","r",stdin),freopen(#p".out","w",stdout)
#define outa(l,r,a) {fo(i,l,r)cout<<a[i]<<" ";cout<<"\n";}
#define BZ {cout<<"-----------------\n";}
#define eb emplace_back
#define ll long long
using namespace std;
void rd(int &x){
	int v(0),op(1);
	register char c=getchar();
	while(c<'0'||'9'<c)op=c=='-'?-1:1,c=getchar();
	while('0'<=c&&c<='9')v=(v<<1)+(v<<3)+(c^48),c=getchar();
	x=v*op; 
}
#define pc(x) putchar(x)
void wt(int x){
	if(x<=9)pc(x+'0');
	else wt(x/10),pc(x%10+'0');
}
const int N=5e5+5;bool isB=1;
int n,Q,x,y,k,ans;
struct qr{int x,y,k;}q[N];
int sum,to[N<<1],nex[N<<1],hd[N],in[N];
void add(int x,int y){to[++sum]=y,nex[sum]=hd[x],hd[x]=sum,in[y]++;}
bool isA(){
	int c1=0;
	fo(i,1,n){
		if(in[i]==1)c1++;
		else if(in[i]>2)return 0;
	}
	if(c1==2)return 1;
	return 0;
}
int fa[N][21],dep[N],p[N<<1],lp,dfn[N],cnt,fp[N];
void dfs(int x,int y){
	fa[x][0]=y,dep[x]=dep[y]+1,dfn[x]=++cnt;
//	p[++lp]=x,fp[x]=lp;
	fo(j,1,20)fa[x][j]=fa[fa[x][j-1]][j-1];
	fe(i,x)if(to[i]!=y){
		dfs(to[i],x);
//		p[++lp]=dep[x];
	}
}
//struct pt{
//	int v,id;
//	friend bool operator<(pt a,pt b){return a.v<b.v;}
//}mxp[N][21],mnp[N][21],f[N<<1][21];
//void getf(){
//	fo(i,1,lp)f[i][0]=(pt){p[i],dep[p[i]]};
//	fo(j,1,20)
//	fo(i,1,lp-(1<<j)+1)f[i][j]=min(f[i][j-1],f[i+(1<<j>>1)][j-1]);
//	fo(i,1,n)mxp[i][0]=mnp[i][0]=(pt){fp[i],i};
//	fo(j,1,20)
//	fo(i,1,n-(1<<j)+1){
//		mnp[i][j]=min(mnp[i][j-1],mnp[i+(1<<j>>1)][j-1]);
//		mxp[i][j]=max(mxp[i][j-1],mxp[i+(1<<j>>1)][j-1]);
//	}
//}
//int qry(int x,int y){
//	if(x>y)swap(x,y);
//	int tp=__lg(y-x+1);
//	return min(f[x][tp],f[y-(1<<tp)+1][tp]).id;
//}
//int qmin(int x,int y){
//	int tp=__lg(y-x+1);
//	return min(mnp[x][tp],mnp[y-(1<<tp)+1][tp]).id;
//}
//int qmax(int x,int y){
//	int tp=__lg(y-x+1);
//	return max(mxp[x][tp],mxp[y-(1<<tp)+1][tp]).id;
//}
int lca(int x,int y){
	if(dep[x]<dep[y])swap(x,y);
	while(dep[x]>dep[y])x=fa[x][__lg(dep[x]-dep[y])];
//	cout<<x<<" "<<y<<"\n";
	if(x==y)return x;
	dfo(i,19,0)if(fa[x][i]!=fa[y][i])x=fa[x][i],y=fa[y][i];
//	while(x!=y)x=fa[x],y=fa[y];
	return fa[x][0];
}
int q2(int x,int y){
	if(x==y)return dep[x];
	int p=lca(x,x+1);
	fo(i,x+2,y)p=lca(p,i);
	return dep[p];
}
void force(){
	dfs(1,0);
//	fo(i,1,lp)cout<<p[i]<<" ";cout<<"\n";
//	fo(i,1,n)cout<<fp[i]<<" "<<dep[i]<<"\n";
//	getf();
//	fo(i,400,n)
//	fo(j,i,n)cout<<i<<" "<<j<<" "<<dep[lca(i,j)]<<" "<<qry(fp[i],fp[j])<<"\n"; 
	fo(I,1,Q){
		x=q[I].x,y=q[I].y,k=q[I].k;
		ans=0;
		fo(i,x,y-k+1){
			ans=max(ans,q2(i,i+k-1));
//			ans=max(ans,qry(qmin(i,i+k-1),qmax(i,i+k-1)));
		}
		wt(ans),pc('\n');
	}
}
int main(){
//	frein;
//	freout;
	fre(query);
	rd(n);
	fo(i,2,n)rd(x),rd(y),add(x,y),add(y,x);
	rd(Q);
	fo(i,1,Q){
		rd(q[i].x),rd(q[i].y),rd(q[i].k);
		if(q[i].k!=q[i].y-q[i].x+1)isB=0;
	}
//	if((n<=5000&&Q<=5000)||isB)
	force();
	return 0;
}
