#include<bits/stdc++.h>

#define fi first
#define se second
//#define int long long

using namespace std;

int read()
{
	int s = 0,f = 1; char x = getchar();
	while(x < '0' || '9' < x) f = (x == '-') ? -1 : 1 , x = getchar();
	while('0' <= x && x <= '9') s = s * 10 + x - '0' , x = getchar();
	return s * f;
}

const int N = 1e6 + 10;

int n,q;
int d[N];
int a[N],m;

pair <int,int> p[N];
vector <int> e[N];
set<int> s;

void dfs0(int x,int fa)
{
	a[++ m] = x;
	d[x] = d[fa] + 1;
	for (int i = 0,v;i < e[x].size();i ++)
	{
		v = e[x][i];
		if (v == fa) continue;
		dfs0(v,x);
	}
	return;
}

int main()
{
	freopen("query.in","r",stdin);
	freopen("query.out","w",stdout);
	
	n = read();
	int mx = 0;
	for (int i = 1,u,v;i < n;i ++)
	{
		u = read();
		v = read();
		e[u].push_back(v);
		e[v].push_back(u);
		p[i].fi = u;
		p[i].se = v;
		d[u] ++;
		d[v] ++;
		mx = max(mx,max(d[u],d[v]));
	}
	
	q = read();
	
	if (mx <= 2)//lian
	{
		int rt = 1;
//		for (int i = n;i >= 1;i --) if (d[i] == 1) rt = i;
		
		dfs0(rt,0);
		while(q --)
		{
			int x = read(),y = read(),k = read();
			int l = x,r = y,ans = 0;
			s.clear();
			for (int i = l;i <= l + k - 1;i ++) s.insert(-d[i]);
			ans = -(*s.rbegin());
			for (int i = l + k;i <= r;i ++)
			{
				s.erase(-d[i - 1]);
				s.insert(-d[i]);
				ans = max(ans,-(*s.rbegin()));
			}
			cout << ans << endl;
		}
		return 0;
	}
	
	return 0;
}

/*
6
1 4
4 5
5 6
6 2
2 3
3
4 6 3
2 5 2
3 4 2

*/
