#include <bits/stdc++.h>
using namespace std;
#define lc(x) x<<1
#define rc(x) x<<1|1
bool X;
int n, q, p, x, y, l, r, k, cnt, t[500010], du[500010], h[500010], dep[500010], dfn[500010], siz[500010], rev[500010], rec[500010], lca[5010][5010], lca2[5010][5010], f[500010][19];
int mn[2000010], mx[2000010];
struct node{
	int x, y, next;
}d[1000010];
struct Ask{
	int l, r, k;
}cun[500010];
struct segment{
	int l, r, ls, rs, mx, len;
}seg[10000010];
void add(int x, int y){
	d[++p].y = y, d[p].next = h[x], h[x] = p;
}
int LCA(int x, int y){
	if (dep[x] < dep[y]) swap(x, y);
	for (int i=18; i>=0; i--){
		if (dep[f[x][i]] >= dep[y]) x = f[x][i];
		if (x == y) return x;
	}
	for (int i=18; i>=0; i--){
		if (f[x][i] != f[y][i]){
			x = f[x][i], y = f[y][i];
		}
	}
	return f[x][0];
}
void pushup(int k){
	mn[k] = min(mn[lc(k)], mn[rc(k)]);
	mx[k] = max(mx[lc(k)], mx[rc(k)]);
}
void build(int k, int l, int r){
	if (l == r){
		mn[k] = mx[k] = dfn[l];
		return ;
	} 
	int mid = l + r >> 1;
	build(lc(k), l, mid);
	build(rc(k), mid+1, r);
	pushup(k);
}
int querymin(int k, int l, int r, int x, int y){
	if (x <= l && r <= y) return mn[k];
	int mid = l + r >> 1, ret = 1e9;
	if (x <= mid) ret = min(ret, querymin(lc(k), l, mid, x, y));
	if (y > mid) ret = min(ret, querymin(rc(k), mid+1, r, x, y));
	return ret; 
}
int querymax(int k, int l, int r, int x, int y){
	if (x <= l && r <= y) return mx[k];
	int mid = l + r >> 1, ret = 0;
	if (x <= mid) ret = max(ret, querymax(lc(k), l, mid, x, y));
	if (y > mid) ret = max(ret, querymax(rc(k), mid+1, r, x, y));
	return ret; 
}
void dfs(int x, int fa){
	dep[x] = dep[fa] + 1;
	dfn[x] = ++dfn[0], siz[x] = 1, rev[dfn[x]] = x;
	for (int i=0; i<18; i++){
		f[x][i+1] = f[f[x][i]][i];
	}
	for (int i=h[x]; i; i=d[i].next){
		int y = d[i].y;
		if (y == fa) continue;
		f[y][0] = x;
		dfs(y, x);
		siz[x] += siz[y]; 
	}
}
void work(){
	dfs(1, 0);
	for (int i=1; i<=n; i++){
		for (int j=dfn[i]; j<=dfn[i]+siz[i]-1; j++){
			lca[i][rev[j]] = lca[rev[j]][i] = i;
		}
		for (int j=h[i]; j; j=d[j].next){
			int y = d[j].y;
			if (dep[y] < dep[i]) continue;
			for (int k=dfn[y]; k<=dfn[y]+siz[y]-1; k++){
				for (int l=dfn[i]+1; l<dfn[y]; l++){
					lca[rev[k]][rev[l]] = i;
				}
				for (int l=dfn[y]+siz[y]; l<=dfn[i]+siz[i]-1; l++){
					lca[rev[k]][rev[l]] = i;
				}
			}
		}
	}
	for (int i=1; i<=n; i++){
		int now = i;
		for (int j=i; j<=n; j++){
			now = lca[now][j];
			lca2[i][j] = now;
		}
	}
	for (int i=1; i<=q; i++){
		scanf ("%d%d%d", &l, &r, &k);
		int ans = 0;
		for (int j=l; j<=r-k+1; j++){
			ans = max(ans, dep[lca2[j][j+k-1]]);
		}
		printf ("%d\n", ans);
	}
}
void work2(){
	dfs(1, 0);
	build(1, 1, n);
	for (int i=1; i<=q; i++){
		l = cun[i].l, r = cun[i].r, k = cun[i].k;
		int posx = rev[querymin(1, 1, n, l, r)], posy = rev[querymax(1, 1, n, l, r)];
		printf ("%d\n", dep[LCA(posx, posy)]);
	}
}
void modify(int &p, int lst, int l, int r, int x){
	seg[p=++cnt]=seg[lst];
	if (l == r){
		seg[p].ls = seg[p].rs = seg[p].mx = seg[p].len = 1;
		return ;
	}
	int mid = l + r >> 1;
	if (x <= mid) modify(seg[p].l, seg[lst].l, l, mid, x);
	else modify(seg[p].r, seg[lst].r, mid+1, r, x);
	seg[p].ls = seg[seg[p].l].ls, seg[p].rs = seg[seg[p].r].ls;
	seg[p].mx = max(seg[seg[p].l].mx, max(seg[seg[p].r].mx, seg[seg[p].l].rs + seg[seg[p].r].ls));
	if (seg[p].ls == mid-l+1) seg[p].ls += seg[seg[p].r].ls;
	if (seg[p].rs == r-mid) seg[p].rs += seg[seg[p].l].rs;
	seg[p].len = r-l+1;
}
segment query(int p, int l, int r, int x, int y){
	if (x <= l && r <= y){
		seg[p].len = r-l+1;
		return seg[p];
	}
	int mid = l + r >> 1;
	if (y <= mid) return query(seg[p].l, l, mid, x, y);
	if (x > mid) return query(seg[p].r, mid+1, r, x, y);
	segment ret;
	segment L = query(seg[p].l, l, mid, x, y), R = query(seg[p].r, mid+1, r, x, y);
	ret.mx = max(L.mx, max(R.mx, L.rs + R.ls));
	ret.ls = L.ls, ret.rs = R.rs;
	ret.len = L.len + R.len;
	if (L.ls == L.len) ret.ls += R.ls;
	if (R.rs == R.len) ret.rs += L.rs;
	return ret;
}
void work3(){
	dfs(1, 0);
	for (int i=1; i<=n; i++){
		rec[dep[i]] = i;
	}
	for (int i=n; i>=1; i--){
		int now = rec[i];
		modify(t[i], t[i+1], 1, n, now);
	}
	for (int i=1; i<=q; i++){
		int l = cun[i].l, r = cun[i].r, k = cun[i].k;
		int L = 1, R = n, ans = 0;
		while (L <= R){
			int mid = L + R >> 1;
			if (query(t[mid], 1, n, l, r).mx >= k) ans = mid, L = mid + 1;
			else R = mid - 1;
		}
		printf ("%d\n", ans);
	}
}
bool Y;
int main(){
	freopen ("query.in", "r", stdin);
	freopen ("query.out", "w", stdout);
	scanf ("%d", &n);
	for (int i=1; i<n; i++){
		scanf ("%d%d", &x, &y);
		du[x] ++, du[y] ++;
		add(x, y); add(y, x);
	}
	scanf ("%d", &q);
	if (n <= 5000) return work(), 0;
	int pdd = 0;
	for (int i=1; i<=q; i++){
		scanf ("%d%d%d", &cun[i].l, &cun[i].r, &cun[i].k);
		if (cun[i].k != cun[i].r-cun[i].l+1) pdd = 1;
	}
	if (!pdd) return work2(), 0;
	int pd = 0, all = 0;
	if (du[1] != 1) pd = 1;
	for (int i=2; i<=n; i++){
		if (du[i] > 2) pd = 1;
		if (du[i] == 1) all ++;
	}
	if (all != 1) pd = 1;
	if (!pd) return work3(), 0;
	return 0;
}
