#include<cstdio>
#include<algorithm>

const int N=5e5+1;

struct Edge {
	int to, next;
}edge[N<<1];
int head[N], cnt;

int n, q;

void add(int u, int v) {
	edge[++cnt].to=v;
	edge[cnt].next=head[u];
	head[u]=cnt;
}

int dep[N];

void dfs(int u, int fa) {
	for(int i=head[u]; i; i=edge[i].next) {
		int v=edge[i].to;
		if(v==fa) {
			continue;
		}
		dep[v]=dep[u]+1;
		printf("%d\n", dep[v]);
		dfs(v, u);
	}
}

int tree[N<<2];

void push_up(int p) {
	tree[p]=std::min(tree[p<<1], tree[p<<1|1]);
}

void build(int p, int pl, int pr) {
	if(pl==pr) {
		tree[p]=dep[pl];
		return;
	}
	
	int mid=pl+pr>>1;
	build(p<<1, pl, mid);
	build(p<<1|1, mid+1, pr);
	push_up(p);
}

int query(int p, int pl, int pr, int L, int R) {
	if(L<=pl&&pr<=R) {
		return tree[p];
	}
	
	int mid=pl+pr>>1, res=0x3f3f3f3f;
	if(L<=mid) {
		res=std::min(res, query(p<<1, pl, mid, L, R));
	}
	if(R>mid) {
		res=std::min(res, query(p<<1|1, mid+1, pr, L, R));
	}
	return res;
}

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