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

const int MXN = 5e5 + 1;

int n, q, ns[MXN], res;
vector< int > g[MXN];
int tp, dfn[MXN], dep[MXN], ip[MXN], lg[MXN << 1], mn[MXN][19], mx[MXN][19], st[MXN << 1][20];
vector< int > euler;
struct node{
	int len, l, r, mx;
}tree[MXN << 2];

int read(){
	int x = 0;
	char c = getchar();
	for(;c < '0' || c > '9';) c = getchar();
	for(;c >= '0' && c <= '9';c = getchar()) x = (x << 1) + (x << 3) + (c ^ 48);
	return x;
}

void dfs(int u, int fa){
	dfn[u] = ++tp;
	ip[u] = euler.size();
	euler.push_back(u);
	for(auto v : g[u])
		if(v != fa){
			dep[v] = dep[u] + 1;
			dfs(v, u);
			euler.push_back(u);
		}
}

int qmn(int l, int r){
	int ll = lg[r - l + 1];
	return dfn[mn[l][ll]] < dfn[mn[r - (1 << ll) + 1][ll]] ? mn[l][ll] : mn[r - (1 << ll) + 1][ll];
}

int qmx(int l, int r){
	int ll = lg[r - l + 1];
	return dfn[mx[l][ll]] > dfn[mx[r - (1 << ll) + 1][ll]] ? mx[l][ll] : mx[r - (1 << ll) + 1][ll]; 
}

int LCA(int l, int r){
	l = ip[l];
	r = ip[r];
	int ll = lg[r - l + 1];
	return dep[euler[st[l][ll]]] < dep[euler[st[r - (1 << ll) + 1][ll]]] ? euler[st[l][ll]] : euler[st[r - (1 << ll) + 1][ll]];
}

node push_up(node x, node y){
	node res;
	res.len = x.len + y.len;
	if(x.mx == x.len) res.l = x.mx + y.l;
	else res.l = x.l;
	if(y.mx == y.len) res.r = x.r + y.mx;
	else res.r = y.r;
	res.mx = max(x.r + y.l, max(x.mx, y.mx));
	return res;
}

int main(){
	freopen("query.in", "r", stdin);
	freopen("query.out", "w", stdout);
	int i, j;
	n = read();
	for(i = 1;i < n;++i){
		int u = read(), v = read();
		g[u].push_back(v);
		g[v].push_back(u);
	}
	dep[1] = 1;
	dfs(1, 0);
	for(i = 1;i <= (n << 1);++i)
		if((1 << lg[i - 1] + 1) == i) lg[i] = lg[i - 1] + 1;
		else lg[i] = lg[i - 1];
	for(i = n;i;--i){
		mn[i][0] = mx[i][0] = i;
		for(j = 1;j < 19;++j){
			int k = i + (1 << j - 1);
			if(k <= n){
				if(dfn[mn[i][j - 1]] < dfn[mn[k][j - 1]]) mn[i][j] = mn[i][j - 1];
				else mn[i][j] = mn[k][j - 1];
				if(dfn[mx[i][j - 1]] > dfn[mx[k][j - 1]]) mx[i][j] = mx[i][j - 1];
				else mx[i][j] = mx[k][j - 1];
			}
			else{
				mn[i][j] = mn[i][j - 1];
				mx[i][j] = mx[i][j - 1];
			}
		}
	}
	for(i = euler.size() - 1;i >= 0;--i){
		st[i][0] = i;
		for(j = 1;j < 20;++j){
			int k = i + (1 << j - 1);
			if(k < euler.size())
				if(dep[euler[st[i][j - 1]]] < dep[euler[st[k][j - 1]]]) st[i][j] = st[i][j - 1];
				else st[i][j] = st[k][j - 1];
			else st[i][j] = st[i][j - 1];
		}
	}
	for(q = read();q;--q){
		int l = read(), r = read(), k = read();
		res = 0;
		for(i = l;i + k - 1 <= r;++i){
			int u = qmn(i, i + k - 1), v = qmx(i, i + k - 1);
			res = max(res, dep[LCA(u, v)]);
		}
		printf("%d\n", res);
	}
	return 0;
}
