#include<cstdio>
#include<vector>
#include<algorithm>
#define N 500005
using namespace std;

int n, fa[N], dep[N], q;
vector<int> e[N];

void dfs(int u) {
	for(auto v: e[u]) {
		if(v == fa[u])	continue;
		fa[v] = u;
		dep[v] = dep[u]+1;
		dfs(v);
	}
}

int main() {
	freopen("query.in", "r", stdin);
	freopen("query.out", "w", stdout);
	scanf("%d", &n);
	for(int i=1, u, v; i<n; ++i) {
		scanf("%d%d", &u, &v);
		e[u].push_back(v);
		e[v].push_back(u);
	}
	dep[1] = 1;
	dfs(1);
	scanf("%d", &q);
	for(int i=1, l, r, k; i<=q; ++i) {
		scanf("%d%d%d", &l, &r, &k);
		int ans = 0;
		for(int ii=l; ii+k-1<=r; ++ii) {
			int res = n+1;
			for(int j=ii; j<=r; ++j) {
				res = min(res, dep[j]);
				if(j-ii+1 >= k)	ans = max(ans, res);
			}
		}
		printf("%d\n", ans);
	}
	return 0;
}

