#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
using namespace std;
const int N = 500005;

int n, q;
struct edge{int to, nxt;} e[N * 2] = {};
int cnte= 0 ;
int head[N] = {};
inline void add(int u, int v) {e[++ cnte] = {v, head[u]}; head[u] = cnte;}

int dep[N] = {};
int fa[N][30] = {};

void dfs(int x, int father){
	dep[x] = dep[father] + 1;
	fa[x][0] = father;
	for(int i=1; i<=25; ++i)  fa[x][i] = fa[fa[x][i-1]][i-1];
	
	for(int i=head[x]; i; i=e[i].nxt)
		if(e[i].to ^ father) 
			dfs(e[i].to, x);
}

int lca(int x, int y){
	if(dep[x] < dep[y]) swap(x, y);
	int dist = dep[x] - dep[y];
	for(int i=0; dist; ++i, dist>>=1)  if(dist&1)  x = fa[x][i];
	if(x == y)  return x;
	for(int i=25; i>=0; --i){
		if(fa[x][i] != fa[y][i]){
			x = fa[x][i];
			y = fa[y][i];
		}
	}
	return fa[x][0];
}

struct Tree{
	int k;
}t[N * 4] = {};

void build(int num, int l, int r){
	if(l == r){
		t[num].k = l;
		return ;
	}
	int mid = (l + r) / 2;
	build(num*2, l, mid);
	build(num*2+1, mid+1, r);
	t[num].k = lca(t[num*2].k, t[num*2+1].k);
}

int query(int num, int l, int r, int L, int R){
	if(r<L || l>R)  return 0;
	if(l>=L && r<=R)  return t[num].k;
	int mid = (l + r) / 2;
	int w1 = query(num*2, l, mid, L, R);
	int w2 = query(num*2+1, mid+1, r, L, R);
	if(w1 == 0)  return w2;
	if(w2 == 0)  return w1;
	return lca(w1, w2);
}

int main(){
	freopen("query.in", "r", stdin);
	freopen("query.out", "w", stdout);
	
	std:: scanf("%d", &n);
	for(int i=1; i<=n-1; ++i){
		int u, v;  std:: scanf("%d%d", &u, &v);
		add(u, v);  add(v, u);
	}
	
	dfs(1, 0);
	build(1, 1, n);
	
	std:: scanf("%d", &q);
	while(q --){
		int l, r, k;  std:: scanf("%d%d%d", &l, &r, &k);
		
		int ans = 0;
		for(int i=l+k-1; i<=r; ++i){
			ans = max(ans, dep[query(1, 1, n, i-k+1, i)]);
		}
		std:: printf("%d\n", ans);
	}
	return 0;
}
