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

signed main() {
	freopen("query.in", "r", stdin);
	freopen("query.out", "w", stdout);
	int n; cin >> n;
	for (int i = 1; i < n; i ++) {
		int u, v; cin >> u >> v;
	} 
	int q; cin >> q;
	while (q --) {
		int l, r, k; cin >> l >> r >> k;
		cout << n - k + 1 << "\n";
	} 
	return 0;
}
