#include <iostream>
#include <algorithm>
#include <cstring>
using namespace std;
const int N = 5e5 + 7;
const int M = 22;

int n;
int x, y;
basic_string<int> g[N];

int dfn[N], dep[N], idx, orz[2*N];

void dfs(int u=1, int f=0) {
	dep[u] = dep[f] + 1;
	orz[++idx] = dep[u];
	dfn[u] = idx;
	for(int& v: g[u]) {
		if(v != f) {
			dfs(v, u);
			orz[++idx] = dep[u];
		}
	}
}

int st[M][2*N], lg[2*N];
void init() {
	lg[1] = 0;
	memset(st, 0x3f, sizeof st);
	for(int i = 2; i < 2*N; ++i)
		lg[i] = lg[i >> 1] + 1;
	for(int i = 1; i <= idx; ++i)
		st[0][i] = orz[i];
	for(int j = 1; j < M; ++j) {
		for(int i = 1 << j; i <= idx; ++i) {
			st[j][i] = min(st[j-1][i], st[j-1][i-(1<<(j-1))]);;
		}
	}
}
int query(int x, int y) {
	int k = lg[y - x + 1];
	return min(st[k][y], st[k][x + (1 << k) - 1]);
}
int lca(int x, int y) {
	if(dfn[x] > dfn[y]) swap(x, y);
	return query(dfn[x], dfn[y]);
}

struct rng {
	int l, r;
};
rng operator + (const rng& x, const rng& y) {
	return {min(x.l, y.l), max(x.r, y.r)};
}
const int INF = 1e9;
rng p[M][N];
void doit() {
	for(int i = 1; i < n; ++i) {
		p[0][i] = {min(dfn[i], dfn[i+1]), max(dfn[i], dfn[i+1])};
	}
	for(int j = 1; j < M; ++j) {
		for(int i = (1 << j); i < n; ++i) {
			p[j][i] = p[j-1][i] + p[j-1][i-(1<<(j-1))];
		}
		for(int i = 0; i < min((1 << j), n); ++i)
			p[j][i] = {INF, 0};
	}
}
rng rquery(int x, int y) {--y;
	int k = lg[y - x + 1]; 
	return p[k][y] + p[k][x + (1 << k) - 1];
}
int work(rng r) {
	return query(r.l, r.r);
}

int main() {
	freopen("query.in", "r", stdin);
	freopen("query.out", "w", stdout);
	ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	cin >> n;
	for(int t = n, x, y; --t; )
		cin >> x >> y, g[x] += y, g[y] += x;
	int flag1 = g[1].size() == 1;
	for(int i = 1; i <= n; ++i)
		flag1 &= g[i].size() <= 2;
//	if(flag1) {
//		solve7();
//		return 0;
//	}
	dfs(1, 0), init(), doit();
	int q; cin >> q;
	for(int l, r, k; q--; ) {
		cin >> l >> r >> k;
		int ans = 0;
		if(k == 1) {
			for(int i = l; i <= r; ++i) {
				ans = max(ans, dep[i]);
			}
		} else
		for(int i = l; i + k - 1 <= r; ++i) {
//			cerr << i << ' ' << i + k - 1 << ' ' 
//			<< rquery(i, i + k - 1).l << rquery(i, i + k - 1).r
//			<< ' ' << work(rquery(i, i + k - 1)) << ' ' << lca(i, i + k -1) << "\n";
//			cerr << dfn[i] << ' ' << dfn[i + k - 1] << "\n";
			ans = max(ans, work(rquery(i, i + k - 1)));
		}
		cout << ans << "\n";
	}
}
