#include <bits/stdc++.h>
using namespace std;

int n;
vector<int> e[100005];
int q;
int l, r, k; 
int p[100005], dep[100005];
struct qry{
	int x, pr;
	qry(int X, int PR){
		x = X, pr = PR;
	}
};
void dfs(){
	queue<qry> q;
	q.push(qry(1, 0));
	while(!q.empty()){
		int x = q.front().x, pr = q.front().pr;
		q.pop();
		p[x] = pr, dep[x] = dep[pr] + 1;
		int cnt = 0;
		for(int i: e[x])
			if(i != pr){
				q.push(qry(i, x));
				cnt++;
			}
	}
	return ;
}
int lca(int x, int y){
	while(dep[x] > dep[y])
		x = p[x];
	while(dep[y] > dep[x])
		y = p[y];
	while(x != y)
		x = p[x], y = p[y];
	return x;
}

int main(){
	freopen("query.in", "r", stdin);
	freopen("query.out", "w", stdout);
	cin >> n;
	for(int i = 1;i < n;i++){
		int u, v;
		cin >> u >> v;
		e[u].push_back(v), e[v].push_back(u);
	}
	dfs();
	cin >> q;
	for(int i = 1;i <= q;i++){
		cin >> l >> r >> k;
		int ans = 0;
		for(int j = l;j <= r - k + 1;j++){
			int pnt = 0;
			for(int a = j;a <= j + k - 1;a++){
				if(pnt == 0)
					pnt = a;
				else
					pnt = lca(a, pnt);
			}
			if(dep[pnt] > ans)
				ans = dep[pnt];
		}
		cout << ans << endl;
	}
	return 0;
}
