#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef double db;
#define mp make_pair
#define fi first
#define se second
template < typename T > void read(T &x) {
	x = 0; char s = getchar(); bool f = 0;
	while (! isdigit(s)) { f |= s == '-'; s = getchar(); }
	while (isdigit(s)) { x = x * 10 + s - 48; s = getchar(); }
	x = f ? -x : x;
}

const int MAXN = 5e5 + 7;

int n;

vector < int > G[MAXN];

void add(int from, int to) {
	G[from].push_back(to);
}

int Fa[MAXN][30], Log[MAXN], Dep[MAXN];
void init() {
	for (int i = 1; i <= MAXN - 7; i ++) Log[i] = Log[i - 1] + (1 << Log[i - 1] == i); 
}
int Log2(int x) { return Log[x] - 1; }

void dfs(int u, int fa) {
	Dep[u] = Dep[fa] + 1, Fa[u][0] = fa;
	for (int i = 1; i <= Log2(Dep[u]); i ++) Fa[u][i] = Fa[Fa[u][i - 1]][i - 1];
	for (auto v : G[u])
		if (v != fa) dfs(v, u);
}
int Lca(int x, int y) {
	if (Dep[x] < Dep[y]) swap(x, y);
	while (Dep[x] != Dep[y]) x = Fa[x][Log2(Dep[x] - Dep[y])];
	if (x == y) return x;
	for (int i = Log2(Dep[x]); i >= 0; i --) 
		if (Fa[x][i] != Fa[y][i]) x = Fa[x][i], y = Fa[y][i];
	return Fa[x][0];
}

int In[MAXN];

const int Inf = 1e9 + 7;

struct Segt_Tree {
	struct Node {
		int minn;
	} t[MAXN << 2];
	#define ls(i) (i << 1)
	#define rs(i) (i << 1 | 1)
	void push_up(int cur) {
		t[cur].minn = min(t[ls(cur)].minn, t[rs(cur)].minn); 
	}
	void build(int cur, int l, int r) {
		if (l == r) {
			t[cur].minn = Dep[l];
			return ;
		}
		int mid = l + r >> 1;
		build(ls(cur), l, mid); build(rs(cur), mid + 1, r);
		push_up(cur);
	}
	int query(int cur, int l, int r, int x, int y) {
		if (x <= l && y >= r) return t[cur].minn;
		int mid = l + r >> 1, ans = Inf;
		if (x <= mid) ans = min(ans, query(ls(cur), l, mid, x, y));
		if (y > mid ) ans = min(ans, query(rs(cur), mid + 1, r, x, y));
		return ans;
	}
} t;

void Solve() {
	dfs(1, 0); t.build(1, 1, n);
	int q; read(q);
	while (q --) {
		int l, r, k;
		read(l); read(r); read(k);
		int ans = 0;
		for (int i = l; i + k - 1 <= r; i ++) {
			int r = i + k - 1;
			int x = t.query(1, 1, n, i, r);
			ans = max(ans, x);
		}
		cout << ans << '\n';
	}
}

int main () {
	freopen("query.in", "r", stdin);
	freopen("query.out", "w", stdout);
	init();
	read(n);
	for (int i = 1; i < n; i ++) {
		int u, v; read(u); read(v);
		add(u, v); add(v, u);
		In[u] ++, In[v] ++; 
	}
	int flg = 0;
	for (int i = 1; i <= n; i ++) flg |= (In[i] >= 3);
	if (! flg) {
		Solve();
		return 0;
	}
	dfs(1, 0);
	int q; read(q);
	while (q --) {
		int l, r, k;
		read(l); read(r); read(k);
		int ans = 0;
		for (int i = l; i + k - 1 <= r; i ++) {
			int u = 0;
			for (int j = i; j <= i + k - 1; j ++) {
				if (! u) u = j;
				else u = Lca(u, j);
				if (j - i + 1 >= k) { ans = max(ans, Dep[u]); continue; }
			}
		}
		cout << ans << '\n';
	}
	return 0;
}
