#include <cstdio>
#include <vector>
using namespace std; 
const int N=5e5+10;
int n,q;
int dep[N];
vector<int> g[N];
int l,r,k;
void dfs(int nd,int fa){
	for(int j=0,nxt;j<g[nd].size();j++){
		nxt=g[nd][j];
		if(nxt==fa) continue;
		dep[nxt]=dep[nd]+1;
	}
}
int max(int a,int b){return a>b?a:b;}
int main(){
	freopen("query.in","r",stdin);
	freopen("query.out","w",stdout);
	scanf("%d",&n);
	for(int i=1,u,v;i<n;i++){
		scanf("%d",&u,&v);
		g[u].push_back(v);
		g[v].push_back(u);
	}
	dep[1]=1;
	dfs(1,0);
	scanf("%d",&q);
	while(q--){
		scanf("%d%d%d",&l,&r,&k);
		printf("%d\n",max(dep[l],dep[r])-k+1);
	}
	return 0;
}
