#include <bits/stdc++.h>
#define ls(x) (x << 1)
#define rs(x) (x << 1 | 1)
#define mid ((l+r) >> 1)
using namespace std;
const int ma = 5e5 + 10,mk = 400;
int n,m;
int siz[ma],fa[ma],dpt[ma],son[ma],top[ma],dfn[ma],dn;
int lg[ma],st[21][ma];
struct EDGE{
	int nxt,to;
}eg[ma << 1];
int head[ma << 1],cnt = 1;
void ad(int u,int v) {
	eg[++cnt] = {head[u],v};head[u] = cnt;
	eg[++cnt] = {head[v],u};head[v] = cnt;
}
void dfs1(int u,int ft) {
	siz[u] = 1;
	fa[u] = ft;
	dpt[u] = dpt[ft] + 1;
	for(int i = head[u]; i; i =eg[i].nxt) {
		int v = eg[i].to;
		if(v == ft)continue;
		dfs1(v,u);
		siz[u] += siz[v];
		if(siz[v] > siz[son[u]]) {
			son[u] = v;
		}
	}
}
void dfs2(int u,int tp) {
	top[u] = tp;
	dfn[u] = ++dn;
	if(!son[u])return;
	dfs2(son[u],tp);
	for(int i = head[u]; i; i =eg[i].nxt) {
		int v = eg[i].to;
		if(v == fa[u] || v == son[u])continue;
		dfs2(v,v);
	}
}
inline int lca(int u,int v) {
	while(top[u] != top[v]) {
		if(dpt[top[u]] < dpt[top[v]]) {
			swap(u,v);
		}
		u = fa[top[u]];
	}
	if(dfn[u] > dfn[v])swap(u,v);
	return u;
}
void pre() {
	dfs1(1,0);
	dfs2(1,1);
	for(int i = 2; i <= n; i++) {
		lg[i] = lg[i >> 1] + 1;
	}
	for(int i = 1; i <= n; i++) {
		st[0][i] = i;
	}
	for(int i = 1; i <= lg[n]; i++) {
		for(int j = 1; j + (1 << i) - 1 <= n; j++) {
			st[i][j] = lca(st[i-1][j],st[i-1][j + (1 << (i-1))]);
		}
	}
}
inline int glca(int l,int r) {
	int d = lg[r-l+1];
	return lca(st[d][l],st[d][r - (1 << d) + 1]);
}
inline int cal(int l,int r,int k) {
	int ans = 1;
	for(int i = l; i <= r-k+1; i++) {
		int lc = glca(i,i+k-1);
		ans = max(ans,dpt[lc]);
	}
	return ans;
}
int tr[mk+1][ma];
inline void push_up(int id,int p) {
	tr[id][p] = max(tr[id][ls(p)],tr[id][rs(p)]);
}
void update(int id,int pos,int val,int l,int r,int p) {
	if(l == r) {
		tr[id][p] = val;
		return;
	}
	if(pos <= mid) {
		update(id,pos,val,l,mid,ls(p));
	} else {
		update(id,pos,val,mid+1,r,rs(p));
	}
	push_up(id,p);
}
int query(int id,int ql,int qr,int l,int r,int p) {
	if(ql <= l && r <= qr) {
		return tr[id][p];
	}
	int ans = 0;
	if(ql <= mid) {
		ans = max(ans,query(id,ql,qr,l,mid,ls(p)));
	}
	if(mid+1 <= qr) {
		ans = max(ans,query(id,ql,qr,mid+1,r,rs(p)));
	}
	return ans;
}
void pre_sq() {
	for(int k = 1; k <= mk; k++) {
		for(int i = 1; i <= n-k+1; i++) {
			update(k,i,cal(i,i+k-1,k),1,n,1);
		}
	}
}
int main() {
	ios::sync_with_stdio(0),ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
	freopen("query.in","r",stdin);
	freopen("query.out","w",stdout);
	cin >> n;
	for(int i = 1,u,v; i < n; i++) {
		cin >> u >> v;
		ad(u,v);
	}
	pre();
	cin >> m;
	if(n > mk) {
		pre_sq();
		while(m--) {
			int l,r,k;
			cin >> l >> r >> k;
			if(k <= mk) {
				cout << query(k,l,r-k+1,1,n,1) << '\n';
				continue;
			}
			cout << cal(l,r,k) << '\n';
		}
		return 0;
	}
	while(m--) {
		int l,r,k;
		cin >> l >> r >> k;
		cout << cal(l,r,k) << '\n';
	}
	return 0;
}
