#include <bits/stdc++.h>

using namespace std;
const int maxn = 500004;
vector<int> to[maxn];
vector<pair<int, int>> dfs_order;
int n, q, cnt, root;
int dfn[maxn], vis[maxn], depth[maxn];

void dfs(int u)
{
	if(vis[u]) return;
	vis[u] = 1;
	if(!dfn[u]) dfn[u] = ++cnt;
	dfs_order.push_back({dfn[u], u});
	for(int v : to[u])
	{
		if(vis[v]) continue;
		depth[v] = depth[u] + 1;
		dfs(v);
		dfs_order.push_back({dfn[u], u});
	}
}

struct nd
{
	int l, r;
	pair<int, int> val;
};
nd segt[10*maxn];

inline int fa(int cur) { return cur>>1; }
inline int lc(int cur) { return cur<<1; }
inline int rc(int cur) { return (cur<<1)+1; }

void push_up(int cur)
{
	segt[cur].val = min(segt[lc(cur)].val, segt[rc(cur)].val);
}

void build(int cur, int l, int r)
{
	segt[cur].l = l;
	segt[cur].r = r;
	if(l == r)
	{
		segt[cur].val = dfs_order[l-1];
		return;
	}
	int mid = (l+r)/2;
	build(lc(cur), l, mid);
	build(rc(cur), mid+1, r);
	push_up(cur);
}

pair<int, int> query(int cur, int l, int r)
{
	if(l <= segt[cur].l && segt[cur].r <= r) return segt[cur].val;
	int mid = (segt[cur].l+segt[cur].r)/2;
	pair<int, int> ret = {0x3f3f3f3f, -1};
	if(l<=mid) ret = min(ret, query(lc(cur), l, r));
	if(r>mid) ret = min(ret, query(rc(cur), l, r));
	return ret;
}

int main()
{
	freopen("query.in", "r", stdin);
	freopen("query.out", "w", stdout);
	scanf("%d", &n);
	for(int i=1;i<=n-1;i++)
	{
		int u, v;
		scanf("%d%d", &u, &v);
		to[u].push_back(v);
		to[v].push_back(u);
	}
	root = 1;
	dfs(root);
	// for(auto u:dfs_order) printf("(dfn=%d, u=%d, depth=%d)\n", u.first, u.second, depth[u.second]);
	build(1, 1, dfs_order.size());
	scanf("%d", &q);
	while(q--)
	{
		int l, r, k;
		scanf("%d%d%d", &l, &r, &k);
		int maxval = -1;
		for(int i=l;i<=n;i++)
		{
			for(int t=k;i+t<=n;t++)
			{
				if(i+k>r) continue;
				int lca = i;
				for(int j=i+1;j<=i+t;j++) lca = query(1, lca, j).second;
				//lca = query(1, i, i+t).second;
				maxval = max(maxval, depth[lca]);
			}
		}
		printf("%d\n", maxval+3);
	}
	return 0;
}

