#include<bits/stdc++.h>

#define mem(x,y) memset(x,y,sizeof(x))
#define rep(i,l,r) for(int i = l;i <= r;i ++)
#define dep(i,l,r) for(int i = l;i >= r;i --)

using namespace std;

int read(){
	int s = 0,w = 1;
	char ch = getchar();
	while(ch < '0' || ch > '9'){if(ch == '-')w = -1;ch = getchar();}
	while(ch >= '0' && ch <= '9')s = s * 10 + ch - '0',ch = getchar();
	return s * w;
}

struct Node{
	int id;
	int dep;
	
	friend bool operator < (Node x,Node y){return x.dep > y.dep;}
}pt[500010];

int n,m;
int dn;
int dfn[1000010];
int mi[21][500010];
int st1[21][500010];
int st2[21][500010];
int dep[1000010];
int pos[1000010];
int du[500010];
int mxd;

vector <int> ed[1000010];

int get(int x,int y){return dfn[x] < dfn[y] ? x : y;}

int get2(int x,int y){return dfn[x] > dfn[y] ? x : y;}

void dfsinit(int x,int fa){
	dep[x] = dep[fa] + 1;
	dfn[x] = ++ dn;
	mi[0][dfn[x]] = fa;
	for(int v : ed[x])if(v != fa)dfsinit(v,x);
}

void init(){
	rep(i,1,n)st1[0][i] = st2[0][i] = i;
	rep(j,1,19){
		rep(i,1,n - (1 << j) + 1){
			mi[j][i] = get(mi[j - 1][i],mi[j - 1][i + (1 << (j - 1))]);
			st1[j][i] = get(st1[j - 1][i],st1[j - 1][i + (1 << (j - 1))]);
			st2[j][i] = get2(st2[j - 1][i],st2[j - 1][i + (1 << (j - 1))]);
		}
	}
}

int lca(int x,int y){
	if(x == y)return x;
	if((x = dfn[x]) > (y = dfn[y]))swap(x,y);
	int lg2 = __lg(y - x);
	x ++;
	return get(mi[lg2][x],mi[lg2][y - (1 << lg2) + 1]);
} 

int qrymin(int l,int r){
	int lg2 = __lg(r - l + 1);
	return get(st1[lg2][l],st1[lg2][r - (1 << lg2) + 1]);
}

int qrymax(int l,int r){
	int lg2 = __lg(r - l + 1);
	return get2(st2[lg2][l],st2[lg2][r - (1 << lg2) + 1]);
}

void solve1(){
	while(m --){
		int l,r,k;
		l = read(),r = read(),k = read();
		int ans = -1;
		rep(i,l,r - k + 1){
			int j = i + k - 1;
			ans = max(ans,dep[lca(qrymin(i,j),qrymax(i,j))]);
		}
		printf("%d\n",ans);
	}
}

struct SegTree{
	struct node{
		int l;
		int r;
		int wl;
		int wr;
		int w;
	}e[11000010],w;
	
	int cnt;
	int rt[500010];
	
	void merge(int i,int l,int r){
		int ls = e[i].l,rs = e[i].r;
		int mid = (l + r) / 2;
		int len1 = mid - l + 1,len2 = r - mid;
		
		if(e[rs].wr == len2)e[i].wr = e[ls].wr + e[rs].wr;
		e[i].wr = max(e[rs].wr,e[i].wr);
		
		if(e[ls].wl == len1)e[i].wl = e[ls].wl + e[rs].wl;
		e[i].wl = max(e[ls].wl,e[i].wl);
		
		e[i].w = max({e[ls].w,e[rs].w,e[ls].wr + e[rs].wl}); 
	} 
	
	void build(int &i,int l,int r){
		i = ++ cnt;
		e[i].wl = e[i].wr = e[i].w = -21474830;
		if(l == r)return ;
		int mid = (l + r) / 2;
		build(e[i].l,l,mid);build(e[i].r,mid + 1,r);
		merge(i,l,r);
	}
	
	void update(int &i,int j,int l,int r,int pos){
		i = ++ cnt;
		e[i] = e[j];
		if(l == r){
			e[i].wl = e[i].wr = e[i].w = 1;
			return ;
		}
		int mid = (l + r) / 2;
		if(pos <= mid)update(e[i].l,e[j].l,l,mid,pos);
		else update(e[i].r,e[j].r,mid + 1,r,pos);
		merge(i,l,r);
	}
	
	node query(int i,int l,int r,int ql,int qr){
		if(ql > qr)return {-1e6,-1e6,-1e6,-1e6,-1e6};
		if(l == ql && r == qr)return e[i];
		int mid = (l + r) / 2;
		if(qr <= mid)return query(e[i].l,l,mid,ql,qr);
		else if(ql > mid)return query(e[i].r,mid + 1,r,ql,qr);
		else {
			node s1 = query(e[i].l,l,mid,ql,mid),s2 = query(e[i].r,mid + 1,r,mid + 1,qr);
			int len1 = mid - l + 1,len2 = r - mid;
			node s;
			if(s2.wr == len2)s.wr = s1.wr + s2.wr;
			s.wr = max(s2.wr,s.wr);
			
			if(s1.wl == len1)s.wl = s1.wl + s2.wl;
			s.wl = max(s1.wl,s.wl);
				
			s.w = max({s1.w,s2.w,s1.wr + s2.wl});
			return s;
		}
	}
}sgt;

void solve2(){
	sgt.build(sgt.rt[0],1,n);
	rep(i,1,n)pt[i].id = i,pt[i].dep = dep[i];
	sort(pt + 1,pt + n + 1);
	int mxdep = -1;rep(i,1,n)mxdep = max(mxdep,dep[i]);
	rep(i,1,n){
		int id = pt[i].id;
		pos[dep[id]] = max(pos[dep[id]],i);
		sgt.update(sgt.rt[i],sgt.rt[i - 1],1,n,id);
	}
	while(m --){
		int L,R,k;
		L = read(),R = read(),k = read();
		int l,r;l = 1,r = mxdep;
		int ans = -1;
		while(l <= r){
			int mid = (l + r) / 2;
			if(sgt.query(sgt.rt[pos[mid]],1,n,L,R).w >= k)l = mid + 1,ans = mid;
			else r = mid - 1;
		}
		printf("%d\n",ans); 
	}
}

signed main(){
	freopen("query.in","r",stdin);
	freopen("query.out","w",stdout);
	cin>>n;
	rep(i,1,n - 1){
		int x,y;
		x = read(),y = read();
		ed[x].push_back(y);
		ed[y].push_back(x);
		du[x] ++,du[y] ++;
		mxd = max({mxd,du[x],du[y]});
	} 
	dfsinit(1,0);
	init();
	cin>>m;
	if(n <= 5000 && m <= 5000)solve1();
	else if(mxd == 2)solve2();
	else solve1();
}

/*

6
5 6
6 1
6 2
2 3
2 4
3
2 5 2
1 4 1
1 6 3

*/
