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

const int N = 5e5 + 10;

int n, dfn[N], _fa[N][21], dep[N], dfc, mx[N][21], mn[N][21], mxpos[N][21], mnpos[N][21], lg[N];
struct edge{
	int v, next;
}edges[N << 1];
int head[N], idx;

void add_edge(int u, int v){
	edges[++idx] = {v, head[u]};
	head[u] = idx;
}

void read(int& x){
	x = 0; char c = getchar();
	while(c < '0' || c > '9') c = getchar();
	while(c >= '0' && c <= '9') x = (x << 3) + (x << 1) + c - '0', c = getchar();
}

void _write(int x){
	if(!x) return;
	_write(x / 10); putchar(x % 10 + '0'); 
}

void write(int x){
	if(x == 0) putchar('0'); 
	_write(x); putchar('\n');
}

void dfs(int u, int fa){
	dep[u] = dep[fa] + 1; _fa[u][0] = fa; dfn[u] = ++dfc;
	for(int i = 1; (1 << i) <= dep[u]; i++) _fa[u][i] = _fa[_fa[u][i - 1]][i - 1];
	for(int i = head[u]; i; i = edges[i].next){
		int v = edges[i].v; if(v == fa) continue; 
		dfs(v, u);
	}
}

int mnq[N], mxq[N], mxh, mxt, mnh, mnt; 

int pdmx(int x, int y){
	if(!x) return y;
	if(dfn[x] > dfn[y]) return x;
	return y;
}
int pdmn(int x, int y){
	if(!x) return y;
	if(dfn[x] < dfn[y]) return x;
	return y;
} 

int Segmin(int l, int r){
	int len = lg[r - l + 1];
	return pdmn(mnpos[l][len], mnpos[r - (1 << len) + 1][len]);
}
int Segmax(int l, int r){
	int len = lg[r - l + 1];
	return pdmx(mxpos[l][len], mxpos[r - (1 << len) + 1][len]);
}

int LCA(int x, int y){
	if(dep[x] < dep[y]) swap(x, y);
	for(int i = 20; i >= 0; i--) if(dep[_fa[x][i]] >= dep[y]) x = _fa[x][i];
	if(x == y) return y;
	for(int i = 20; i >= 0; i--) if(_fa[x][i] != _fa[y][i]) x = _fa[x][i], y = _fa[y][i];
	return _fa[x][0];
}

void solve(){
	int l, r, k; cin >> l >> r >> k; 
	int ans = 0, p1 = 0, p2 = 0;
	for(int i = l + k - 1; i <= r; i++){
		p1 = Segmax(i - k + 1, i), p2 = Segmin(i - k + 1, i);
		ans = max(ans, dep[LCA(p1, p2)]);
	} write(ans);
}

signed main(){
	freopen("query.in", "r", stdin);
	freopen("query.out", "w", stdout);
//	system("fc query.out query3.ans");
	read(n);
	for(int i = 2; i <= n; i++) lg[i] = lg[i >> 1] + 1;
	for(int i = 1; i < n; i++){
		int x, y; read(x); read(y);
		add_edge(x, y); add_edge(y, x);
	}
	dfs(1, 0);
	for(int i = n; i; i--){
		mxpos[i][0] = mnpos[i][0] = i;
		for(int j = 1; j <= 20; j++){
			mxpos[i][j] = pdmx(mxpos[i][j - 1], mxpos[i + (1 << j - 1)][j - 1]);
			mnpos[i][j] = pdmn(mnpos[i][j - 1], mnpos[i + (1 << j - 1)][j - 1]);
		}
	}
	int T; read(T); while(T--) solve();

	return 0;
}

