#include<bits/stdc++.h>
using namespace std;
vector<int> nodes[514514];
int n, l, r, k, fa[514514][30], depth[514514], q, id[2014514], cnt[514514];
void dfs(int pos, int x){
	fa[pos][0] = x;
	depth[pos] = depth[x] + 1;
	for(int i = 1; 1 << i <= depth[pos]; i++){
		fa[pos][i] = fa[fa[pos][i - 1]][i - 1];
	}
	for(int i = 0; i < (int)nodes[pos].size(); i++){
		if(nodes[pos][i] != x){
			dfs(nodes[pos][i], pos);
		}
	}
}
int lca(int a, int b){
	if(depth[b] > depth[a]){
		swap(a, b);
	}
	for(int i = 20; i >= 0; i--){
		if(depth[fa[a][i]] >= depth[b]){
			a = fa[a][i];
		}
	}
	if(a == b){
		return a;
	}
	for(int i = 20; i >= 0; i--){
		if(fa[a][i] != fa[b][i]){
			a = fa[a][i], b = fa[b][i];
		}
	}
	return fa[a][0];
}
void build(int l, int r, int pos){
	int mid = (l + r) / 2;
	if(l == r){
		id[pos] = l;
		return;
	}
	build(l, mid, pos * 2);
	build(mid + 1, r, pos * 2 + 1);
	id[pos] = lca(id[pos * 2], id[pos * 2 + 1]);
	return;
}
int ask(int l, int r, int nl, int nr, int pos){
	int mid = (nl + nr) / 2, lid = 0, rid = 0;
	if(l <= nl && r >= nr){
		return id[pos];
	}
	if(l <= mid){
		lid = ask(l, r, nl, mid, pos * 2);
	}
	if(r > mid){
		rid = ask(l, r, mid + 1, nr, pos * 2 + 1);
	}
	if(rid != 0 && lid != 0){
		return lca(rid, lid);
	}
	if(rid != 0){
		return rid;
	}
	return lid;
}
void SpecialA(){
	cin >> q;
	deque<int> d, tim;
	int ans = 0;
	for(int i = 1; i <= n; i++){
		cin >> l >> r >> k;
		d.clear(), tim.clear();
		for(int j = l; j <= l + k - 1; j++){
			while(depth[j] < d.back()){
				d.pop_back();
				tim.pop_back();
			}
			d.push_back(depth[j]);
			tim.push_back(j);
		}
		ans = d.front();
		for(int j = l + k; j <= r; j++){
			while(j - tim.front() >= k){
				tim.pop_front();
				d.pop_front();
			}
			while(depth[j] < d.back()){
				d.pop_back();
				tim.pop_back();
			}
			d.push_back(depth[j]);
			tim.push_back(j);
			ans = max(ans, d.front());
		}
		cout << ans << '\n';
	}
}
int main(){
	ios::sync_with_stdio(0);
	cin.tie(0), cout.tie(0);
	freopen("query.in", "r", stdin);
	freopen("query.out", "w", stdout);
	cin >> n;
	for(int i = 1; i < n; i++){
		cin >> l >> r;
		cnt[l]++;
		cnt[r]++;
		nodes[l].push_back(r);
		nodes[r].push_back(l);
	}
	int flag = 1;
	for(int i = 1; i <= n; i++){
		if(cnt[i] != 2){
			flag = 0;
			break;
		}
	}
	dfs(1, 0);
	if(flag){
		SpecialA();
		return 0;
	}
	depth[0] = 0;
	build(1, n, 1);
	cin >> q;
	for(int i = 1; i <= q; i++){
		cin >> l >> r >> k;
		if(k == r - l + 1){
			cout << depth[ask(l, r, 1, n, 1)] << '\n';
		}
		else{
			int ans = 0;
			for(int j = l; j + k - 1 <= r; j++){
				int lk = ask(j, j + k - 1, 1, n, 1);
				if(depth[lk] > ans){
					ans = depth[lk];
				}
			}
			cout << ans << '\n';
		}
	}
	return 0;
}
