#include<bits/stdc++.h>
using namespace std;
#define sdgt(x) ((x) <= '9' && (x) >= '0')

int n, u, v, dfst[500005][19], dt, dd[500005], dfs[500005], lgtmp, q, tmp, d, ddn[500005];
vector<int> ed[500005];
char c;
int l, r, ans, nw, nn;

inline void read(int&x){
	x = 0;
	c = getchar();
	while(!sdgt(c)) c = getchar();
	while(sdgt(c)){
		x = (x<<1)+(x<<3)+c-48;
		c = getchar();
	}
}

inline int lg2(int x){
	lgtmp = -1;
	while(x) x >>= 1, ++lgtmp;
	return lgtmp;
}

void dfsget(int id, int fa, int deep){
	dfst[++dt][0] = fa;
	dd[id] = deep;
	dfs[id] = dt;
	for(register int i : ed[id]) if(i != fa) dfsget(i, id, deep+1);
}

inline int lcadget(int l, int r){
	if(l == r) return dd[l];
	l = dfs[l];
	r = dfs[r];
	if(r < l) swap(l, r);
	l++;
	tmp = lg2(r-l+1);
	return min(dd[dfst[l][tmp]], dd[dfst[r-(1<<tmp)+1][tmp]]);
}

int main(){
	freopen("query.in", "r", stdin);
	freopen("query.out", "w", stdout);
	
	register int i;
	read(n);
	for(int i = 1;i < n;i++){
		read(u);
		read(v);
		ed[u].push_back(v);
		ed[v].push_back(u);
	}
	dfsget(1, 0, 1);
	tmp = lg2(n);
	for(int j = 1;j <= tmp;j++){
		u = n-(1<<j)+1;
		for(i = 1;i <= u;i++){
			dfst[i][j] = ((dd[dfst[i][j-1]] < dd[dfst[i+(1<<(j-1))][j-1]]) ? dfst[i][j-1] : dfst[i+(1<<(j-1))][j-1]);
		}
	}
	read(q);
	
//	for(i = 1;i <= n;i++){
//		cout << dd[i] << ' ';
//	}
//	cout << endl;
//	for(i = 1;i <= n;i++){
//		cout << dfs[i] << " ";
//	}
//	cout << endl;
//	for(i = 0;i <= tmp;i++){
//		for(int j = 1;j <= n;j++){
//			cout << dfst[j][i] << ' ';
//		}
//		cout << endl;
//	}
	
	for(i = 2;i <= n;i++) ddn[i] = lcadget(i-1, i);
	
	while(q--){
		read(u);
		read(v);
		read(d);
		ans = 0;
		if(d == 1){
			for(u;u<=v;u++) ans = max(dd[u], ans);
		}
		else{
			v = v-d+2;
			for(l = u+1;l <= v;l++){
				nw = n+1;
				for(i = 1;i < d;i++){
					nw = min(nw, ddn[l+i-1]);
				}
				ans = max(ans, nw);
			}
		}
		printf("%d\n", ans);
	}
	return 0;
}
