// 线段树合并？二分答案！感觉调不出来！写部分分！ 
// 完了，两个log 带样例2.1s，滚去写 C了 
#include <iostream>
#include <cstring>
#include <algorithm>
#include <queue>
#include <ctime>
//#define int long long
#define x first
#define y second
using namespace std;
typedef pair<int, int> PII;
const int N = 5e5 + 10;
bool Mst;
int n, dep[N], pos[N], dfn[N], fa[N], timestamp, q;
struct owo {
	int l, r, k, id;
} qr[N];
int ans[N];
vector<int> g[N];
// 单点修改，区间最大 1 子段
struct qwq {
	int l, r, lm, rm, dat, sum;
} tr[N << 2];
#define mid ((l + r) >> 1)
qwq up(qwq l, qwq r) {
	qwq u; u.l = l.l, u.r = r.r;
	u.lm = (l.sum == l.r - l.l + 1) ? (l.r - l.l + 1 + r.lm) : l.lm;
	u.rm = (r.sum == r.r - r.l + 1) ? (r.r - r.l + 1 + l.rm) : r.rm;
	u.sum = l.sum + r.sum;
	u.dat = max({l.dat, r.dat, l.rm + r.lm});
	return u;
}
void up(int u) {
	tr[u] = up(tr[u << 1], tr[u << 1 | 1]);
}
void build(int u, int l, int r) {
	tr[u] = {l, r, 0, 0, 0, 0};
	if(l == r) return ;
	build(u << 1, l, mid), build(u << 1 | 1, mid + 1, r);
}
void update(int u, int x, int v) {
	int l = tr[u].l, r = tr[u].r;
	if(l == r) return tr[u].lm = tr[u].rm = tr[u].dat = tr[u].sum = v, void();
	if(x <= mid) update(u << 1, x, v);
	else update(u << 1 | 1, x, v);
	up(u);
}
qwq query(int u, int ql, int qr) {
	int l = tr[u].l, r = tr[u].r;
	if(ql <= l && qr >= r) return tr[u];
	if(ql <= mid && qr > mid) return up(query(u << 1, ql, qr), query(u << 1 | 1, ql, qr));
	if(ql <= mid) return query(u << 1, ql, qr);
	return query(u << 1 | 1, ql, qr); 
}
#undef mid
void dfs(int u, int f) {
//	cout << u << ' ' << f << endl;
	dfn[u] = ++ timestamp, pos[timestamp] = u, dep[u] = dep[f] + 1, fa[u] = f;
	for(auto v : g[u])
		if(v != f) dfs(v, u);
}
int lg[N];
int Min(int a, int b) {return dfn[a] < dfn[b] ? a : b;}
namespace Yui {
	int st[20][N];
	void ST() {
		for(int i = 2; i < N; i ++) lg[i] = lg[i >> 1] + 1;
		for(int i = 1; i <= n; i ++) st[0][i] = fa[pos[i]];
		for(int i = 1; i <= lg[n]; i ++) 
			for(int j = 1; j + (1 << i) - 1 <= n; j ++) 
				st[i][j] = Min(st[i - 1][j], st[i - 1][j + (1 << i - 1)]);
	}
} ;
int LCA(int a, int b) {
	if(a == b) return a;
	if((a = dfn[a]) > (b = dfn[b])) swap(a, b);
	int k = lg[b - a];
	return Min(Yui::st[k][a + 1], Yui::st[k][b - (1 << k) + 1]);
}
namespace Sub1 {
	int st[20][N][2];
	void ST() {
		for(int i = 1; i <= n; i ++) st[0][i][0] = st[0][i][1] = dfn[i];
		for(int i = 1; i <= lg[n]; i ++) 
			for(int j = 1; j + (1 << i) - 1 <= n; j ++) 
				st[i][j][0] = min(st[i - 1][j][0], st[i - 1][j + (1 << i - 1)][0]),
				st[i][j][1] = max(st[i - 1][j][1], st[i - 1][j + (1 << i - 1)][1]);
	}
	int RMQ(int l, int r, int op) {
		int k = lg[r - l + 1];
		return (op ? max(st[k][l][op], st[k][r - (1 << k) + 1][op]) : min(st[k][l][op], st[k][r - (1 << k) + 1][op]));
	}
	void main() {
		ST();
		for(int i = 1; i <= q; i ++) {
			int l = qr[i].l, r = qr[i].r, k = qr[i].k;
			int ans = 0;
			for(int ll = l; ll + k - 1 <= r; ll ++) 
				ans = max(ans, dep[LCA(pos[RMQ(ll, ll + k - 1, 0)], pos[RMQ(ll, ll + k - 1, 1)])]);
			cout << ans << '\n';
		}
	}
} ;
namespace Chain {
	void init() {
		int p = 1;
		for(int i = 1, f = 0; i <= n; i ++) {
			dfn[p] = ++ timestamp, pos[timestamp] = p, dep[p] = dep[f] + 1, fa[p] = f;
			f = p;
			if(p == 1 || i == n) p = g[p][0];
			else p = (g[p][0] ^ g[p][1] ^ fa[p]);
		}
	}
	void solve(int l, int r, vector<owo> Q) {
		if(l > r) return ;
		if(l == r) {
			for(auto o : Q) ans[o.id] = l;
			return ;
		}
		int mid = l + r >> 1;
		for(int i = mid + 1; i <= r; i ++) update(1, pos[i], 1);
		vector<owo> L, R;
		for(auto o : Q) {
			if(query(1, o.l, o.r).dat >= o.k) R.push_back(o);
			else L.push_back(o);
		}
		for(int i = mid + 1; i <= r; i ++) update(1, pos[i], 0);
		solve(mid + 1, r, R);
		for(int i = mid + 1; i <= r; i ++) update(1, pos[i], 1);
		solve(l, mid, L);
	}
	void main() {
		init();
//		for(int i = 1; i <= n; i ++)
//			cout << pos[i] << ' '; cout << '\n';
		build(1, 1, n);
		vector<owo> tmp;
		for(int i = 1; i <= q; i ++) tmp.push_back(qr[i]);
		solve(1, n, tmp);
		for(int i = 1; i <= q; i ++) cout << ans[i] << '\n';
	}
}
bool Med;
signed main() {
	freopen("query.in", "r", stdin);
	freopen("query.out", "w", stdout);
	ios::sync_with_stdio(0), cin.tie(0);
	cerr << (abs(&Mst - &Med) / 1048576.0) << "Mb\n";
	clock_t stt = clock();
	cin >> n;
	bool flg = 1;
	for(int i = 1, a, b; i < n; i ++)
		cin >> a >> b, g[a].push_back(b), g[b].push_back(a);
	for(int i = 1; i <= n; i ++) 
		if(g[i].size() > 2) flg = 0;
	cin >> q;
	for(int i = 1; i <= q; i ++) cin >> qr[i].l >> qr[i].r >> qr[i].k, qr[i].id = i;
	if(n == 1) {
        for(int i = 1; i <= q; i ++)
            cout << 1 << '\n';
        return 0;
	}
	if(flg) {
		Chain::main();
		cerr << (1.0 * clock() - stt) / CLOCKS_PER_SEC << "s\n";
		return 0; 
	}
	dfs(1, 0);
	Yui::ST();
	Sub1::main();
	
	return 0;
}


