#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll read()
{
	ll x=0,f=1;
	char ch=getchar();
	while(ch<'0' || ch>'9')
	{
		if(ch=='-')
		{
			f=-1;
		}
		ch=getchar();
	}
	while(ch>='0' && ch<='9')
	{
		x=(x<<3)+(x<<1)+ch-'0';
		ch=getchar();
	}
	return f*x;
}
ll fa[500010];
ll find(ll x,ll sum)
{
	if(fa[x]!=x)
	{
		sum+=find(fa[x],sum);
		return sum;
	}
	else
		return sum;
}
int main()
{
	freopen("query.in","r",stdin);
	freopen("query.out","w",stdout);
	ll n=read();
	for(int i=1;i<=n;i++)
	{
		fa[i]=i;
	}
	for(int i=1;i<n;i++)
	{
		ll x=read(),y=read();
		fa[x]=y;
	}
	ll q=read();
	while(q--)
	{
		ll l=read(),r=read(),k=read();
		if(abs(find(l,1)-find(r,1))>=k)
		{
			printf("%lld\n",min(find(l,1),find(r,1)));
		}
		else
		{
			printf("%lld\n",max(find(l,1),find(r,1))-k);
		}
	}
	return 0;
}
