#include<bits/stdc++.h>
typedef long long LL;
typedef double dl;
#define opt operator
#define pb push_back
#define pii std::pair<LL,LL>
const LL maxn=1e6+9,mod=998244353,inf=0x3f3f3f3f;
LL Read(){
	LL x(0),f(1); char c=getchar();
	while(c<'0' || c>'9'){
		if(c=='-') f=-1; c=getchar();
	}
	while(c>='0' && c<='9'){
		x=(x<<3ll)+(x<<1ll)+c-'0'; c=getchar();
	}return x*f;
}
void Chkmin(LL &x,LL y){
	if(y<x) x=y;
}
void Chkmax(LL &x,LL y){
	if(y>x) x=y;
}
LL add(LL x,LL y){
	return x+=y,x>=mod?x-mod:x;
}
LL dec(LL x,LL y){
	return x-=y,x<0?x+mod:x;
}
LL mul(LL x,LL y){
	return 1ll*x*y%mod;
}
LL Pow(LL base,LL b){
	LL ret(1); while(b){
		if(b&1) ret=mul(ret,base); base=mul(base,base); b>>=1;
	}return ret;
}
namespace Sgt{
	LL sum[2000000];
	void Build(LL nw,LL l,LL r){
		sum[nw]=0;
		if(l==r) return;
		LL mid(l+r>>1);
		Build(nw<<1,l,mid); Build(nw<<1|1,mid+1,r);
	}
	LL Query(LL nw,LL l,LL r,LL lt,LL rt){
		if(lt<=l && rt>=r) return sum[nw];
		LL mid(l+r>>1),ret(0);
		if(lt<=mid) ret+=Query(nw<<1,l,mid,lt,rt);
		if(rt>mid) ret+=Query(nw<<1|1,mid+1,r,lt,rt);
		return ret;
	}
	void Modify(LL nw,LL l,LL r,LL x){
		sum[nw]++;
		if(l==r) return;
		LL mid(l+r>>1);
		if(x<=mid) Modify(nw<<1,l,mid,x);
		else Modify(nw<<1|1,mid+1,r,x);
	}
}
struct Qy{
	LL x,y,z;
}qy[maxn];
LL n,ret1,m,tim;
LL size[maxn],dep[maxn],top[maxn],fa[maxn],inc[maxn][21],son[maxn],dfn[maxn],pos[maxn];
std::vector<LL> V[maxn];
std::vector<pii> S[maxn];
std::vector<LL> Q[maxn];
void Dfs1(LL u,LL f){
	dep[u]=dep[f]+1;
	inc[u][0]=f;
	for(LL i=1;i<=20;++i) inc[u][i]=inc[inc[u][i-1]][i-1];
	size[u]=1;
	for(LL i=0;i<V[u].size();++i){
		LL v(V[u][i]); if(v==f) continue;
		Dfs1(v,u);
		size[u]+=size[v];
		if(size[v]>size[son[u]]){
			son[u]=v;
		}
	}
}
void Dfs2(LL u,LL f,LL tp){
	fa[u]=f;
	dfn[u]=++tim; pos[tim]=u;
	top[u]=tp;
	if(son[u]){
		Dfs2(son[u],u,tp);
	}
	for(LL i=0;i<V[u].size();++i){
		LL v(V[u][i]); if(v==f || v==son[u]) continue;
		Dfs2(v,u,v);
	}
}
std::map<pii,LL> mp;
void Dfs3(LL u,LL f){
	static LL id[maxn],cnt[maxn];
	LL tmp(0);
	for(LL i=0;i<V[u].size();++i){
		LL v(V[u][i]); if(v==f) continue;
		Dfs3(v,u);
		id[v]=++tmp;
	}
	for(LL i=0;i<S[u].size();++i){
		LL x(S[u][i].first),y(S[u][i].second);
		if(x!=u){
			ret1+=cnt[x];
			cnt[x]++;
		}
		if(y!=u){
			ret1+=cnt[y];
			cnt[y]++;
		}
		if(x!=u && y!=u){
			assert(x!=y);
			if(id[x]>id[y]) std::swap(x,y);
			ret1-=mp[pii(x,y)];
			mp[pii(x,y)]++;
		}
	}
}
LL Lca(LL x,LL y){
	if(dep[x]<dep[y]) std::swap(x,y);
	for(LL i=20;i>=0;--i) if(dep[inc[x][i]]>=dep[y]) x=inc[x][i];
	if(x==y) return x;
	for(LL i=20;i>=0;--i) if(inc[x][i]!=inc[y][i]){
		x=inc[x][i]; y=inc[y][i];
	}
	return inc[x][0];
}
LL Up(LL x,LL len){
	for(LL i=20;i>=0;--i) if((len>>i)&1) x=inc[x][i];
	return x;
}
LL Query(LL x,LL y){
	LL ret(0);
	while(top[x]!=top[y]){
		if(dep[top[x]]<dep[top[y]]) std::swap(x,y);
		ret+=Sgt::Query(1,1,n,dfn[top[x]],dfn[x]);
		x=fa[top[x]];
	}
	if(dep[x]>dep[y]) std::swap(x,y);
	ret+=Sgt::Query(1,1,n,dfn[x],dfn[y]);
	return ret;
}
void Modify(LL x){
	Sgt::Modify(1,1,n,dfn[x]);
}
int main(){
	n=Read();
	for(LL i=1;i<n;++i){
		LL x(Read()),y(Read());
		V[x].pb(y); V[y].pb(x);
	}
	Dfs1(1,0);
	Dfs2(1,0,1);
	m=Read();
	for(LL i=1;i<=m;++i){
		LL x(Read()),y(Read());
		LL z(Lca(x,y));
		Q[dep[z]].pb(i);
		qy[i]=(Qy){x,y,z};
	}
	Sgt::Build(1,1,n);
	LL ret(0);
	for(LL i=n;i>=1;--i){
		LL sz(Q[i].size()); if(!sz) continue;
		static LL cnt[maxn];
		for(LL j=0;j<Q[i].size();++j){
			LL nw(Q[i][j]);
			LL x(qy[nw].x),y(qy[nw].y),z(qy[nw].z);
			ret+=cnt[z];
			cnt[z]++;
			ret+=Query(x,z)+Query(y,z);
		}
		for(LL j=0;j<Q[i].size();++j){
			LL nw(Q[i][j]);
			LL x(qy[nw].x),y(qy[nw].y),z(qy[nw].z);
			Modify(z);
		}
	}
	Sgt::Build(1,1,n);
	ret1=0;
	for(LL i=n;i>=1;--i){
		for(LL j=0;j<Q[i].size();++j){
			LL nw(Q[i][j]);
			LL x(qy[nw].x),y(qy[nw].y),z(qy[nw].z);
			ret1+=Query(x,z)+Query(y,z);
		}
		for(LL j=0;j<Q[i].size();++j){
			LL nw(Q[i][j]);
			LL x(qy[nw].x),y(qy[nw].y),z(qy[nw].z);
			if(x!=z){
				LL len(dep[x]-dep[z]-1);
				x=Up(x,len);
				Modify(x);
			}
			if(y!=z){
				LL len(dep[y]-dep[z]-1);
				y=Up(y,len);
				Modify(y);
			}
			S[z].pb(pii(x,y));
		}
	}
	Dfs3(1,0);
//	printf("%d %d\n",ret,ret1);
	printf("%lld\n",ret-ret1);
	return 0;
}