#include<bits/stdc++.h>
#pragma GCC optimize(3)

using namespace std;

#define gc c=getchar()
#define r(x) read(x)
#define ll long long

#define getchar() (frS==frT&&(frT=(frS=frBB)+fread(frBB,1,1<<12,stdin),frS==frT)?EOF:*frS++)
char frBB[1<<12],*frS=frBB,*frT=frBB;

template<typename T>
inline void read(T &x){
	x=0;char gc;
	while(!isdigit(c)){if(c=='-')gc;}
	while(isdigit(c)){x=x*10+c-'0';gc;}
}

const int N=3e5+7;

bool vis[N];
int f[N];
int son[N];

struct Triple{
	int lca,u,v;
}A[N];

struct Table1{
	int ecnt;
	int fir[N<<1],nex[N<<1],to[N<<1];

	inline void addedge(int u,int v){
		nex[++ecnt]=fir[u],fir[u]=ecnt,to[ecnt]=v;
		nex[++ecnt]=fir[v],fir[v]=ecnt,to[ecnt]=u;
	}
}G;

struct Table2{
	int ecnt;
	int fir[N<<1],nex[N<<1],to[N<<1],ID[N<<1];

	inline void addedge(int u,int v,int w){
		nex[++ecnt]=fir[u],fir[u]=ecnt,to[ecnt]=v,ID[ecnt]=w;
	}
}Q1,Q2;

int find(int x){
	return x==f[x]?x:f[x]=find(f[x]);
}

ll ans;
int cnt1[N];
int cnt2[N];
unordered_map<ll,int>cnt3;
int cnt4[N];

void dfs1(int x,int fa){
	vis[x]=1;
	for(int i=Q1.fir[x];i;i=Q1.nex[i]){
		if(!vis[Q1.to[i]])continue;
		int v=Q1.to[i];
		int ID=Q1.ID[i];
		int lca=find(v);
		cnt4[lca]-=2;
		A[ID]={lca,v,x};
		Q2.addedge(v,lca,ID);
		Q2.addedge(x,lca,ID);
	}
	for(int i=G.fir[x];i;i=G.nex[i]){
		int v=G.to[i];
		if(v==fa)continue;
		dfs1(v,x);
		f[v]=x;
	}
}

void dfs2(int x,int fa){
	for(int i=Q2.fir[x];i;i=Q2.nex[i]){
		int lca=Q2.to[i];
		int ID=Q2.ID[i];
		if(A[ID].u==x)A[ID].u=son[lca];
		else A[ID].v=son[lca];
	}
	for(int i=G.fir[x];i;i=G.nex[i]){
		int v=G.to[i];
		if(v==fa)continue;
		son[x]=v;
		dfs2(v,x);
		cnt4[x]+=cnt4[v];
	}
}

inline ll s(int x){
	return (ll)x*(x-1)>>1;
}

int main(){
	// freopen(".in","r",stdin);
	// freopen(".out","w",stdout);
	// clock_t start=clock();
	int n;r(n);
	for(int i=1;i<n;++i){
		int u,v;r(u),r(v);
		G.addedge(u,v);
	}
	int m;r(m);
	for(int i=1;i<=m;++i){
		int u,v;r(u),r(v);
		if(u==v)A[i]={u,0,0};
		else {
			++cnt4[u],++cnt4[v];
			Q1.addedge(u,v,i);
			Q1.addedge(v,u,i);
		}
	}
	for(int i=1;i<=n;++i){
		f[i]=i;
	}
	dfs1(1,0);
	dfs2(1,0);
	for(int i=1;i<=m;++i){
		int lca=A[i].lca;
		int u=A[i].u;
		int v=A[i].v;
		++cnt1[lca];
		if(u)++cnt2[u];
		if(v)++cnt2[v];
		if(u&&v)++cnt3[(ll)u*n+v];
	}
	for(int i=1;i<=n;++i)ans+=(ll)cnt1[i]*cnt4[i]-(ll)cnt2[i]*(cnt4[i]-cnt2[i])+s(cnt1[i])-s(cnt2[i]);
	for(auto i:cnt3)ans+=s(i.second);
	printf("%lld\n",ans);
	// cerr<<(double)(clock()-start)/CLOCKS_PER_SEC<<endl;
	return 0;
}