#include<bits/stdc++.h>
#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 ll long long
#define V inline void
#define I inline int
#define vi vector<int>
#define pb push_back
using namespace std;
const int N=5e5+10;
char ST;
I read() {
	int x(0),y(1);
	char c=getchar();
	while(c<48||c>57) {
		if(c==45)y=-1;c=getchar();
	}
	while(c>=48&&c<=57) x=(x<<1)+(x<<3)+(c^48),c=getchar();
	return x;
}
int dep[N],fa[N],n,f[N][20],g[N][20],dfn[N],lg[N],q,dft;
vi G[N];
V dfs(int x) {
	f[dfn[x]=++dft][0]=fa[x];
	dep[x]=dep[fa[x]]+1;
	for(int y:G[x]) if(y^fa[x]) fa[y]=x,dfs(y);
}
I get(int x,int y) {
	return dfn[x]<dfn[y]?x:y;
}
I lca(int x,int y) {
	if(x==y) return x;
	if((x=dfn[x])>(y=dfn[y])) swap(x,y);
	x++;int k=lg[y-x+1];
	return get(f[x][k],f[y-(1<<k)+1][k]);
}
I ask(int x,int y) {
	int k=lg[y-x+1];
	return lca(g[x][k],g[y-(1<<k)+1][k]);
}
namespace Task2 {
	int rk[N],rt[N],cnt,ls[N*19],rs[N*19];
	struct tree {
		int len,mx,lmx,rmx;
	}tr[N*19];
	tree merge(tree x,tree y) {
		tree z;
		z.mx=max({x.mx,y.mx,x.rmx+y.lmx});
		z.lmx=x.lmx;if(x.len==x.lmx) z.lmx+=y.lmx;
		z.rmx=y.rmx;if(y.len==y.rmx) z.rmx+=x.rmx;
		z.len=x.len+y.len;
		return z;
	}
	I nw(int x) {
		++cnt;tr[cnt]=tr[x];ls[cnt]=ls[x];rs[cnt]=rs[x];return cnt;
	}
	V add(int &x,int l,int r,int px,int py) {
		x=nw(x);
		if(l==r) {
			tr[x].len=1;
			tr[x].mx=tr[x].lmx=tr[x].rmx=py;
			return ;
		}
		int mid=l+r>>1;
		if(px<=mid) add(ls[x],l,mid,px,py);
		else add(rs[x],mid+1,r,px,py);
		tr[x]=merge(tr[ls[x]],tr[rs[x]]);
	}
	tree ques(int x,int l,int r,int pl,int pr) {
		if(l>pr||r<pl) return {0,0,0,0};
		if(l>=pl&&r<=pr) return tr[x];
		int mid=l+r>>1;
		return merge(ques(ls[x],l,mid,pl,pr),ques(rs[x],mid+1,r,pl,pr));
	}
	V solve() {
		fo(i,1,n) rk[dep[i]]=i;
		fd(i,n,1) {
			rt[i]=rt[i+1];
			add(rt[i],1,n,rk[i],1);
		}
		q=read();
//		scanf("%d",&q);
		while(q--) {
			int l=read(),r=read(),k=read();
//			scanf("%d%d%d",&l,&r,&k);
			int le=1,ri=n,ans=1;
			while(le<=ri) {
				int mid=le+ri>>1;
				if(ques(rt[mid],1,n,l,r).mx>=k) ans=mid,le=mid+1;
				else ri=mid-1;
			}
			printf("%d\n",ans);
		}
	}
}
char ED;
int main() {
//	return system("fc query.out query3.ans"),0;
	freopen("query.in","r",stdin);
	freopen("query.out","w",stdout);
//	scanf("%d",&n);
	n=read();
	fo(i,1,n-1) {
		int x=read(),y=read();
//		scanf("%d%d",&x,&y);
		G[x].pb(y);G[y].pb(x);
	}
	dfs(1);
	int bj=G[1].size()==1;
	fo(i,1,n) bj&=G[i].size()<=2;
	if(bj) return Task2::solve(),0;
	fo(i,2,n) lg[i]=lg[i>>1]+1;
	fo(i,1,n) g[i][0]=i;
	fo(i,1,lg[n]) fo(j,1,n-(1<<i)+1) f[j][i]=get(f[j][i-1],f[j+(1<<i-1)][i-1]);
	fo(i,1,lg[n]) fo(j,1,n-(1<<i)+1) g[j][i]=lca(g[j][i-1],g[j+(1<<i-1)][i-1]);
//	scanf("%d",&q);
	q=read();
	while(q--) {
		int l=read(),r=read(),k=read();
//		scanf("%d%d%d",&l,&r,&k);
		int ans(0);
		fo(i,l,r-k+1) ans=max(ans,dep[ask(i,i+k-1)]);
		printf("%d\n",ans);
	}
	return 0;
}
