#include <bits/stdc++.h>
//#define DEBUG
#define N (int)(5e5+3)
using namespace std;

bool flag = 1;
int n, q, ans, tmp, tmp2, x, y, z, du[N], lft[N], rght[N];
int cur, head[N], nxt[N<<1], to[N<<1];
int fa[N], top[N], siz[N], hson[N], dep[N];
int seg_mx[N], seg_mn[N];

inline void add(int u, int v) {
	to[++cur] = v;
	nxt[cur] = head[u];
	head[u] = cur;
}

inline void dfs1(int u, int f, int d) {
	siz[u] = 1, fa[u] = f, dep[u] = d;
	for(int i=head[u]; i; i=nxt[i]) {
		if(to[i] == f)
			continue;
		dfs1(to[i], u, d+1);
		if(siz[to[i]] > siz[hson[u]])
			hson[u] = to[i];
		siz[u] += siz[to[i]];
	} 
}

inline void dfs2(int u, int t) {
	top[u] = t;
	if(hson[u] != 0)
		dfs2(hson[u], t);
	for(int i=head[u]; i; i=nxt[i]) {
		if(to[i]==fa[u] || to[i]==hson[u])
			continue;
		dfs2(to[i], to[i]);
	}
}

inline int lca(int u, int v) {
	while(top[u] != top[v]) {
		if(dep[top[u]] > dep[top[v]])
			swap(u, v);
		v = fa[top[v]];
	}
	if(dep[u] <= dep[v])
		return u;
	else
		return v;
}

inline void pushup(int u) {
	seg_mx[u] = max(seg_mx[u<<1], seg_mn[u<<1|1]);
	seg_mn[u] = min(seg_mn[u<<1], seg_mn[u<<1|1]);
}

inline void build(int u, int l, int r) {
	if(l == r) {
		seg_mx[u] = seg_mn[u] = dep[l];
		return;
	}
	int mid = (l+r)>>1;
	build(u<<1, l, mid);
	build(u<<1|1, mid+1, r);
	pushup(u);
}

inline int getmx(int u, int l, int r, int s, int t) {
	if(s<=l && r<=t)
		return seg_mx[u];
	int mid = (l+r)>>1, ret = 0;
	if(s <= mid)
		ret = max(ret, getmx(u<<1, l, mid, s, t));
	if(t >= mid+1)
		ret = max(ret, getmx(u<<1|1, mid+1, r, s, t));
	return ret; 
}

inline int getmn(int u, int l, int r, int s, int t) {
	if(s<=l && r<=t)
		return seg_mn[u];
	int mid = (l+r)>>1, ret = INT_MAX;
	if(s <= mid)
		ret = min(ret, getmn(u<<1, l, mid, s, t));
	if(t >= mid+1)
		ret = min(ret, getmn(u<<1|1, mid+1, r, s, t));
	return ret; 
}

inline bool check(int dpp) {
	for(int i=x; i<=y; i++) {
		if(dep[i] != dpp)
			continue;
		if(min(rght[i], y) - max(lft[i], x) + 1 >= z)
			return true; 
	}
	return false;
}

inline void fnd(int l, int r) {
	if(l > r)
		return;
	int mid = (l+r)>>1;
	if(check(mid)) {
		ans = mid;
		fnd(mid+1, r);
	} else
		fnd(l, mid-1);
}

int main() {
	freopen("query.in", "r", stdin);
	freopen("query.out", "w", stdout);
	scanf("%d", &n);
	for(int i=1; i<n; i++) {
		scanf("%d%d", &x, &y);
		add(x, y), add(y, x);
		if(++du[x] > 2 || ++du[y] > 2)
			flag = 0;
	}
	if(flag == 1) {
		dep[1] = 1;
		int now = to[head[1]], lst = 1;
		while(du[now] > 1) {
			dep[now] = dep[lst]+1;
			for(int i=head[now]; i; i=nxt[i]) {
				if(to[i] == lst)
					continue;
				lst = now;
				now = to[i];
				break;
			}
		} 
		dep[now] = dep[lst]+1;
		build(1, 1, n);
		for(int i=1; i<=n; i++) {
			lft[i] = rght[i] = i;
			if(i >= 2) {
				while(lft[i]-1>=1 && dep[lft[i]-1]>dep[i])
					lft[i] = lft[lft[i]-1];
			}
		}
		for(int i=n-1; i>=1; i--) {
			while(rght[i]+1<=n && dep[rght[i]+1]>dep[i])
				rght[i] = rght[rght[i]+1];
		}
	} else {
		dfs2(1, 1);
		dfs1(1, 0, 1);
	}
	scanf("%d", &q);
	for(int i=1; i<=q; i++) {
		scanf("%d%d%d", &x, &y, &z);
		if(flag != 1) {
			ans = 0;
			for(int j=x; j+z-1<=y; j++) {
				tmp = j;
				for(int k=j+1; k<=j+z-1; k++)
					tmp = lca(tmp, k);
				if(dep[tmp] > dep[ans])
					ans = tmp;
			}
		} else {
			tmp = getmn(1, 1, n, x, y);
			tmp2 = getmx(1, 1, n, x, y);
			fnd(tmp, tmp2);
		}
		printf("%d\n", dep[ans]);
	}
	return 0;
}
