#include <iostream>
#include <cstdio>
#define ls (x << 1)
#define rs (x << 1 | 1)
#define mid ((l + r) >> 1)
using namespace std;

int n,q;
int to[1000010],nxt[1000010],head[500010],cnt,maxdep;
int dep[500010],dfn[500010],dfncnt,fa[25][500010];
struct node
{
	int xl,xr,minn;
	int lf,rt;
	int maxn,lef,rit;
} tree[2000010];
int ans;
struct que
{
	int l,r,k,id;
} qu[500010],R[500010],L[500010];
int Ans[500010];

void add(int x,int y)
{
	to[++ cnt] = y;
	nxt[cnt] = head[x];
	head[x] = cnt;
}

void dfs(int x,int la)
{
	dep[x] = dep[la] + 1;
	maxdep = max(maxdep,dep[x]);
	dfn[x] = ++ dfncnt;
	fa[0][x] = la;
	for (int i = 1;i <= 20;i ++) fa[i][x] = fa[i - 1][fa[i - 1][x]];
	for (int i = head[x];i;i = nxt[i])
	{
		int u = to[i];
		if (u == la) continue;
		dfs(u,x);
	}
}

int lca(int x,int y)
{
	if (dep[x] < dep[y]) swap(x,y);
	int tmp = dep[x] - dep[y];
	for (int i = 20;~i;i --) if (tmp >> i & 1) x = fa[i][x];
	if (x == y) return x;
	for (int i = 20;~i;i --) if (fa[i][x] != fa[i][y]) x = fa[i][x],y = fa[i][y];
	return fa[0][x];
}

void build(int x,int l,int r)
{
	tree[x].xl = l,tree[x].xr = r;
	tree[x].minn = n + 1;
	tree[x].lf = tree[x].rt = 0;
	if (l == r) return ;
	build(ls,l,mid),build(rs,mid + 1,r);
}

void pushup(int x)
{
	int l = tree[x].xl,r = tree[x].xr;
	tree[x].minn = min(tree[ls].minn,tree[rs].minn);
	if (tree[ls].rt && tree[rs].lf) tree[x].minn = min(tree[x].minn,dep[lca(tree[ls].rt,tree[rs].lf)]);
	tree[x].lf = (tree[ls].lf ? tree[ls].lf : tree[rs].lf);
	tree[x].rt = (tree[rs].rt ? tree[rs].rt : tree[ls].rt);
	tree[x].maxn = max(tree[ls].maxn,tree[rs].maxn);
	tree[x].maxn = max(tree[x].maxn,tree[ls].rit + tree[rs].lef);
	tree[x].lef = tree[ls].lef + (tree[ls].lef == mid - l + 1) * tree[rs].lef;
	tree[x].rit = tree[rs].rit + (tree[rs].rit == r - mid) * tree[ls].rit;
}

void upd(int x,int qx,int y)
{
	int l = tree[x].xl,r = tree[x].xr;
	if (l == r)
	{
		tree[x].lf = tree[x].rt = y;
		tree[x].minn = dep[y];
		return ;
	}
	if (qx <= mid) upd(ls,qx,y);
	else upd(rs,qx,y);
	pushup(x);
}

void del(int x,int qx)
{
	int l = tree[x].xl,r = tree[x].xr;
	if (l == r)
	{
		tree[x].lf = tree[x].rt = 0;
		tree[x].minn = n + 1;
		return ;
	}
	if (qx <= mid) del(ls,qx);
	else del(rs,qx);
	pushup(x);
}

void uupd(int x,int qx,int y)
{
//	int l = tree[x].xl,r = tree[x].xr;
//	if (l == r)
//	{
//		if (y) tree[x].lef = tree[x].rit = tree[x].maxn = 1;
//		else tree[x].lef = tree[x].rit = tree[x].maxn = 0;
//		return ;
//	}
//	if (qx <= mid) uupd(ls,qx,y);
//	else uupd(rs,qx,y);
//	pushup(x);
}

//int query(int x,int ql,int qr)
//{
////	int l = tree[x].xl,r = tree[x].xr;
////	if (l >= ql && r <= qr) return tree[x];
////	if (qr <= mid) return query(ls,ql,qr);
////	if (mid < ql) return query(rs,ql,qr);
////	node xx = query(ls,ql,qr),yy = query(rs,ql,qr);
////	node res;
////	res.maxn = max(xx.maxn,max(yy.maxn,xx.rit + yy.lef));
////	res.lef = xx.lef + (xx.lef == mid - ql + 1) * yy.lef;
//	return 0;
//}

#undef mid

//void solve(int ql,int qr,int al,int ar)
//{
//	if (al == ar)
//	{
//		for (int i = ql;i <= qr;i ++) Ans[qu[i].id] = al;
//		return ;
//	}
//	int mid = ((al + ar) >> 1);
//	for (int i = 1;i <= n;i ++)
//		if (dfn[i] >= mid) uupd(1,i,1);
//		else uupd(1,i,0);
//	int ll = 0,rr = 0;
//	for (int i = ql;i <= qr;i ++)
//		if (query(1,qu[i].l,qu[i].r) >= qu[i].k) R[++ rr] = qu[i];
//		else L[++ ll] = qu[i];
//	for (int i = 1;i <= ll;i ++) qu[ql + i - 1] = L[i];
//	for (int i = 1;i <= rr;i ++) qu[ql + ll + i] = R[i];
//	solve(ql,ql + ll - 1,al,mid - 1),solve(ql + ll,qr,mid,ar);
//}

int main()
{
	freopen("query.in","r",stdin);
	freopen("query.out","w",stdout);
	scanf("%d",&n);
	for (int i = 1;i < n;i ++)
	{
		int x,y;
		scanf("%d%d",&x,&y);
		add(x,y),add(y,x);
	}
	dfs(1,0);
	scanf("%d",&q);
	if (n <= 5000 && q <= 5000)
	{
		build(1,1,n);
		while (q --)
		{
			int l,r,k;
			scanf("%d%d%d",&l,&r,&k);
			ans = 0;
			for (int i = l;i <= r;i ++)
			{
				upd(1,dfn[i],i);
				if (i >= l + k - 1) ans = max(ans,tree[1].minn),del(1,dfn[i - k + 1]);
				if (i == r)
				{
					for (int j = r - k + 2;j <= r;j ++) del(1,dfn[j]);
				}
			}
			printf("%d\n",ans);
		}
		return 0;
	}
//	if (maxdep == n)
//	{
//		build(1,1,n);
//		for (int i = 1;i <= q;i ++) scanf("%d%d%d",&qu[i].l,&qu[i].r,&qu[i].k),qu[i].id = i;
//		solve(1,n,1,n);
//		for (int i = 1;i <= q;i ++) printf("%d\n",Ans[i]);
//		return 0;
//	}
}
