#include<bits/stdc++.h>
#define ll long long
using namespace std;

inline ll read() {
	ll res=0,f=0;
	char c;
	do {
		c=getchar();
		f|=c=='-';
	} while(!isdigit(c));
	do {
		res=(res<<1)+(res<<3)+(c^48);
		c=getchar();
	} while(isdigit(c));
	return f?-res:res;
}

void write(ll x) {
	if(x<0) x=-x,putchar('-');
	if(x>9) write(x/10);
	putchar(x%10+48);
}

const ll N=1e6+10,MOD=1e9+7;

struct node {
	ll to,next;
} Edge[N<<1];
ll head[N],cnt;

inline void add(ll x,ll y) {
	Edge[++cnt]= {y,head[x]};
	head[x]=cnt;
}

ll son[N],siz[N],fa[N],deep[N];

void dfs1(ll u,ll f) {
	fa[u]=f;
	deep[u]=deep[f]+1;
	siz[u]=1;
	ll maxsize=-1;
	for(ll i=head[u],to; i; i=Edge[i].next) {
		to=Edge[i].to;
		if(to==f) continue;
		dfs1(to,u);
		siz[u]+=siz[to];
		if(siz[to]>maxsize) {
			maxsize=siz[to];
			son[u]=to;
		}
	}
}

ll dfn[N],tim,top[N];

void dfs2(ll u,ll t) {
	top[u]=t;
	dfn[u]=++tim;
	if(!son[u])
		return ;
	dfs2(son[u],t);
	for(ll i=head[u],to; i; i=Edge[i].next) {
		to=Edge[i].to;
		if(to==fa[u]||to==son[u]) continue;
		dfs2(to,to);
	}
}

inline ll get_lca(ll x,ll y) {
	while(top[x]!=top[y]) {
		if(deep[top[x]]<deep[top[y]]) {
			x^=y;
			y^=x;
			x^=y;
		}
		x=fa[top[x]];
	}
	return deep[x]>deep[y]?y:x;
}

ll n;

inline void work() {
	n=read();
	for(ll i=1,u,v; i<n; i++) {
		u=read(),v=read();
		add(u,v);
		add(v,u);
	}
	dfs1(1,1);
	dfs2(1,1);
	ll q=read();
	while(q--) {
		ll l=read(),r=read(),k=read();
		ll lca=get_lca(l,r);
		write(deep[lca]);
		putchar('\n');
	}
}

int main() {
	freopen("query.in","r",stdin);
	freopen("query.out","w",stdout);
	work();
	fclose(stdin);
	fclose(stdout);
	return 0;
}
