#include <bits/stdc++.h>
#define left rt * 2
#define right rt * 2 + 1
#define pii pair <int, int> 
using namespace std;
int read(){
	int s = 0, f = 1;char ch = getchar();
	while(!isdigit(ch)){if(ch == '-')f = -1;ch = getchar();}
	while(isdigit(ch)){s = s * 10 + ch - '0';ch = getchar();}
	return s * f;
}
const int MAXN = 5e5 + 5, MR = 2e6 + 5;
struct edge{
	int from, to, nxt;
}e[MR];
int n, m, ct, cnt, flag, lpos[MAXN], rpos[MAXN], xpos[MAXN], ans[MAXN], id[MAXN];
int head[MAXN], f[MAXN][21], dep[MAXN], deg[MAXN], lc[5005][5005];
int st[MAXN][21], lg[MAXN];
vector <int> vc, vc2[MAXN];
void add_edge(int u, int v){
	e[++ cnt] = {u, v, head[u]};
	head[u] = cnt;
}
void bfs(){
	queue <pii> q;
	q.push({1, 0});
	while(!q.empty()){
		int x = q.front().first, fa = q.front().second;
		id[x] = ++ ct;
		q.pop();
		dep[x] = dep[fa] + 1, vc2[dep[x]].push_back(x);
		f[x][0] = fa;
		for(int i = 1;(1 << i) <= dep[x];i ++)f[x][i] = f[f[x][i - 1]][i - 1];
		for(int i = head[x];i;i = e[i].nxt){
			int v = e[i].to;
			if(v == fa)continue;
			q.push({v, x});
		}
	}
}
int lca(int x, int y){
	if(dep[x] < dep[y])swap(x, y);
	for(int i = 19;i >= 0;i --){
		if(dep[x] - dep[y] >= (1 << i))x = f[x][i];
	}
	if(x == y)return x;
	for(int i = 19;i >= 0;i --){
		if(f[x][i] != f[y][i])x = f[x][i], y = f[y][i];
	}
	return f[x][0];
}
int query(int l, int r){
	int len = lg[r - l + 1];
	return lca(st[l][len], st[r - (1 << len) + 1][len]);
}
struct node{
	int x, y, z;
};
struct Segment_tree{
	int lf[MR], rf[MR], num[MR], lsum[MR], rsum[MR];
	void push_up(int rt){
		num[rt] = max({num[left], num[right], rsum[left] + lsum[right]});
		lsum[rt] = lsum[left];
		if(num[left] == (rf[left] - lf[left] + 1))
			lsum[rt] = (rf[left] - lf[left] + 1) + lsum[right], num[rt] = max(num[rt], (rf[left] - lf[left] + 1) + lsum[right]);
		rsum[rt] = rsum[right];
		if(num[right] == (rf[right] - lf[right] + 1))
			rsum[rt] = (rf[right] - lf[right] + 1) + rsum[left], num[rt] = max(num[rt], (rf[right] - lf[right] + 1) + rsum[left]);
		if(num[rt] == rf[rt] - lf[rt] + 1)lsum[rt] = rsum[rt] = num[rt];
	}
	void build(int rt, int l, int r){
		lf[rt] = l, rf[rt] = r;
		if(l == r)return ;
		int mid = l + r >> 1;
		build(left, l, mid);
		build(right, mid + 1, r);
	}
	void change_node(int rt, int x, int y){
		if(x > rf[rt] || lf[rt] > x)return ;
		if(lf[rt] == x && rf[rt] == x){
			num[rt] = lsum[rt] = rsum[rt] = y;
			return ;
		}
		change_node(left, x, y);
		change_node(right, x, y);
		push_up(rt);
	}
	node query(int rt, int l, int r){
		if(l > rf[rt] || r < lf[rt])return {0, 0, 0};
		if(l <= lf[rt] && rf[rt] <= r)return {num[rt], lsum[rt], rsum[rt]};
		node lp = query(left, l, r), rp = query(right, l, r);
		node tmp = {0, 0, 0};
		tmp.x = max({lp.x, rp.x, lp.z + rp.y});
		tmp.y = lp.y, tmp.z = rp.z;
		return tmp;
	}
}tr;
void solve(vector <int> g, int l, int r){
	if(r < l)return ;
	if(l == r){
		for(int v : g)ans[v] = l;
		return ;
	}
	vector <int> lg, rg;
	int mid = l + r >> 1;
	for(int i = mid + 1;i <= r;i ++){
		for(int v : vc2[i])tr.change_node(1, id[v], 1);
	}
	for(int v : g){
		int h = tr.query(1, lpos[v], rpos[v]).x;
//		printf("%d %d %d\n", l, r, h);
		if(h >= xpos[v])rg.push_back(v);
		else lg.push_back(v);
	}
	solve(lg, l, mid);
	for(int i = mid + 1;i <= r;i ++){
		for(int v : vc2[i])tr.change_node(1, id[v], 0);
	}
	solve(rg, mid + 1, r);
}
int main(){
	freopen("query2.in", "r", stdin);
	freopen("query2.out", "w", stdout);
	n = read(), flag = 1;
	for(int i = 1;i < n;i ++){
		int u = read(), v = read();
		deg[u] ++, deg[v] ++;
		if(deg[u] > 2)flag = 0;
		if(deg[v] > 2)flag = 0;
		add_edge(u, v);
		add_edge(v, u);
	}
	m = read();
	for(int i = 2;i <= n;i ++)lg[i] = lg[i / 2] + 1;
	bfs();
	if(flag){
		tr.build(1, 1, n);
		for(int i = 1;i <= m;i ++)
			lpos[i] = read(), rpos[i] = read(), xpos[i] = read(), vc.push_back(i);
//		tr.change_node(1, 1, 1);
//		tr.change_node(1, 2, 1);
//		tr.change_node(1, 3, 1);
//		printf("%d\n", tr.query(1, 1, 3).x);
		solve(vc, 1, n);
		for(int i = 1;i <= m;i ++)printf("%d\n", ans[i]);
		return 0;
	}
	for(int i = 1;i <= n;i ++)st[i][0] = i;
	for(int i = 1;i <= lg[n] + 1;i ++){
		for(int j = 1;j + (1 << i - 1) <= n;j ++)
			st[j][i] = lca(st[j][i - 1], st[j + (1 << i - 1)][i - 1]);
	}
	for(int i = 1;i <= m;i ++){
		int l = read(), r = read(), k = read(), res = 0;
		for(int j = l;j + k - 1 <= r;j ++)res = max(res, dep[query(j, j + k - 1)]);
		printf("%d\n", res);
	}
	return 0;
}

