#include<bits/stdc++.h>
using namespace std;
typedef pair<int,int> PII;
const int N = 1e6 + 10;
int idx,nxt[N],d[N],h[N],rd[N];
int tree[N],dep[N],fa[N];
int dfn[N],wz[N],d1;
map <PII,int> mp,mm;
int n,q;
void add(int x,int y)
{
	idx++;
	d[idx] = y;
	nxt[idx] = h[x];
	rd[y]++;
	h[x] = idx;
}
void dfs(int x,int da)
{
	dep[x] = dep[da] + 1;
	dfn[++d1] = x;
	wz[x] = d1;
	fa[x] = da;
	for(int i = h[x];i;i = nxt[i])
	{
		if(d[i] == da)
			continue;
		dfs(d[i],x);
	}
}
void build(int now,int l,int r)
{
	if(l == r)
	{
		tree[now] = dfn[l];
		return ;
	}
	int mid = (l + r) >> 1;
	build(now * 2,l,mid);
	build(now * 2 + 1,mid + 1,r);
	tree[now] = (dep[tree[now * 2]] < dep[tree[now * 2 + 1]]) ? tree[now * 2] : tree[now * 2 + 1];
}
int find(int now,int l,int r,int al,int ar)
{
	if(al <= l && r <= ar)
		return tree[now];
	if(r < al || ar < l || l > r)
		return -1;
	int mid = (l + r) >> 1;
	int t = find(now * 2,l,mid,al,ar);
	int t1 = find(now * 2 + 1,mid + 1,r,al,ar);
	if(t * t1 < 0)
		return t + t1 + 1;
	return (dep[t] < dep[t1]) ? t : t1;
}
//void le()
//{
//	int t,t1,t2;
//	cin >> q;
//	for(int i = 1;i <= n;i++)
//		build(1,1,n,dep[i]);
//	for(int i = 1;i <= n;i++)
//	{
//		cin >> t >> t1 >> t2;
//		cout << find(1,1,n,t,t1,t2) << '\n';
//	}
//}
int main()
{
	freopen("query.in","r",stdin);
	freopen("query.out","w",stdout);
	ios::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL);
	int t,t1,t2,t3 = 1,ans;
	cin >> n;
	for(int i = 1;i < n;i++)
	{
		cin >> t >> t1;
		add(t,t1);
		add(t1,t);
		if(rd[t1] > 2 || rd[t] > 2)
			t3 = 0;
	}
	if(t3)
	{
//		le();
		return 0;
	}
	dfs(1,0);
	build(1,1,n);
//	for(int i = 1;i <= n;i++)
//		cout << dfn[i] << " ";
//	cout << '\n';
//	for(int i = 1;i <= n;i++)
//		cout << wz[i] << " ";
//	cout << '\n';
//	cout << fa[find(1,1,n,min(wz[3],wz[5]) + 1,max(wz[3],wz[5]))];
	cin >> q;
	PII tt;
	for(int i = 1;i <= q;i++)
	{
		cin >> t >> t1 >> t2;
		ans = 0;
		for(int len = t2;len <= t1 - t + 1;len++)
		{
			for(int l = t,r = l + len - 1;r <= t1;l++)
			{
				r = l + len - 1;
				if(r > t1)
					break;
				t3 = l;
				if(!mm[{l,r}])
				{
					for(int u = l + 1;u <= r;u++)
					{
						tt = {min(t3,u),max(t3,u)};
						if(!mp[tt])
							mp[tt] = fa[find(1,1,n,min(wz[t3],wz[u]) + 1,max(wz[t3],wz[u]))];
						t3 = mp[tt];
					}
					mm[{l,r}] = t3;
				}
				else
					t3 = mm[{l,r}];
				ans = max(ans,dep[t3]);
			}
		}
		cout << ans << '\n';
	}
	return 0;
}
