#include <bits/stdc++.h>
using namespace std;
const int N = 5e5;
const int inf = 1e9;
typedef long long ll;
const ll INF = 1e15;
int read() {
	int s = 0,f = 1;char ch = getchar();
	while (!isdigit(ch)) f = ch == '-' ? -1 : 1, ch = getchar();
	while (isdigit(ch)) s = s * 10 + ch - '0', ch = getchar();
	return s * f;
}
//bool sst;
int n;
struct edge {
	int v,nxt;
}ed[N * 2 + 10];
int head[N + 10],cnt;
void add(int u,int v) {
	ed[++cnt] = {v,head[u]};
	head[u] = cnt;
}
int dep[N + 10],dfn[N + 10],tot,rnk[N + 10],fl;
pair<int,int> st[20][N + 10];
void dfs(int x,int fa) {
	st[0][tot] = {dep[x],fa}, dfn[x] = ++tot;
	rnk[tot] = x;
	int ct = 0;
	for (int i = head[x];i;i = ed[i].nxt) {
		int v = ed[i].v;
		if (v == fa) continue;
		dep[v] = dep[x] + 1;
		ct ++;
		dfs(v,x);
	}
	fl &= (ct <= 1);
}
int lg[N + 10];
int LCA(int x,int y) {
	if (x == y) return x;
	x = dfn[x],y = dfn[y];
	if (x > y) swap(x,y); y --;
	int len = lg[y - x + 1];
	return min(st[len][x],st[len][y - (1 << len) + 1]).second;
}
int st2[20][N + 10],st3[20][N + 10];
int query(int l,int r) {
	pair<int,int> mn = {inf,0},mx = {-inf,0};
	for (int i = l;i <= r;i ++ ) mn = min(mn,{dfn[i],i}), mx = max(mx,{dfn[i],i});
	return dep[LCA(mn.second,mx.second)] + 1;
}
struct node {
	int v,lv,rv,len;
	inline friend node operator + (const node &l,const node &r) {
//		node res;
//		res.lv = ;
//		res.rv = ;
//		res.v = ;
//		res.len = ;
		return {max({l.v,r.v,l.rv + r.lv}),l.lv == l.len ? l.lv + r.lv : l.lv,r.rv == r.len ? r.rv + l.rv : r.rv,l.len + r.len};
	}
};
struct Seg {
	int l,r;
	node v;
}t[N * 20 + 10];
#define ls t[x].l
#define rs t[x].r
int Cnt;
void pushup(int x) {
	t[x].v = t[ls].v + t[rs].v;
}
void modify(int &x,int l,int r,int k) {
	t[++Cnt] = t[x], x = Cnt;
	t[x].v = {0,0,0,0};
	if (l == r) {
		t[x].v = {1,1,1,1};
		return;
	}
	int mid = l + r >> 1;
	if (mid >= k) modify(ls,l,mid,k);
	else modify(rs,mid + 1,r,k);
	pushup(x);
}
node query(int x,int l,int r,int L,int R) {
	if (L >= l && r >= R) return t[x].v;
	int mid = L + R >> 1;
	if (mid < l) return query(rs,l,r,mid + 1,R);
	if (mid >= r) return query(ls,l,r,L,mid);
	return query(ls,l,r,L,mid) + query(rs,l,r,mid + 1,R);
}
int rt[N + 10];
inline bool check(int mid,int l,int r,int k) {
	return query(rt[mid],l,r,1,n).v >= k;
}
//bool eed;
int main() {
//	cout << (&sst-&eed) / (1 << 20);
//	system("fc query.out query2.ans");
	freopen("query.in","r",stdin);
	freopen("query.out","w",stdout);
	n = read();
	lg[0] = -1;
	for (int i = 1;i <= n;i ++ ) lg[i] = lg[i >> 1] + 1;
	for (int i = 1;i < n;i ++ ) {
		int u = read(),v = read();
		add(u,v), add(v,u);
	}
	fl = 1;
	dfs(1,0);
//	cout << fl << endl;
//		return 0;
	if (fl) {
//		return 0;
		for (int i = n;i;i -- ) rt[i] = rt[i + 1], modify(rt[i],1,n,rnk[i]);
		int q = read();
		while (q -- ) {
			int l = read(),r = read(),k = read();
			int L = 1,R = n;
			while (L < R) {
				int mid = L + R + 1 >> 1;
				if (check(mid,l,r,k)) L = mid;
				else R = mid - 1;
			}
			printf("%d\n",L);
		}
		return 0;
	}
	for (int i = 1;i <= 19;i ++ )
		for (int j = 1;j + (1 << i) - 1 <= n;j ++ )
			st[i][j] = min(st[i - 1][j],st[i - 1][j + (1 << i - 1)]);
	int q = read();
	while (q -- ) {
		int l = read(),r = read(),k = read();
		int ans = 0;
		for (int i = l;i + k - 1 <= r;i ++ ) {
			ans = max(ans,query(i,i + k - 1));
		}
		printf("%d\n",ans);
	}
	return 0;
}
