#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#define N 600005
#define lowbit(x) x&-x
#define mp make_pair
#define int long long
using namespace std;
int read()
{
	int 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^48);ch=getchar();}
	return x*f;
}
int n,m,tot,v[N],head[N],nxt[N],cnt,dfn[N],dfstime,fa[N][25],dep[N],rfn[N],b[N],ans;
struct node
{
	int lca,a,b,x,y;
}q[N];
struct BIT
{
	int c[N];
	void modify(int x,int k){for(;x<=n;x+=lowbit(x))c[x]+=k;}
	int query(int x){int res=0;for(;x;x-=lowbit(x))res+=c[x];return res;}
}t;
void add(int a,int b)
{
	v[++cnt]=b;
	nxt[cnt]=head[a];
	head[a]=cnt;
}
void dfs(int x,int fath)
{
	dep[x]=dep[fath]+1;dfn[x]=++dfstime;
	for(int i=0;i<=19;i++)fa[x][i+1]=fa[fa[x][i]][i];
	for(int i=head[x];i;i=nxt[i])
	{
		if(v[i]==fath)continue;
		fa[v[i]][0]=x;
		dfs(v[i],x);
	}
	rfn[x]=dfstime;
}
pair<int,int> lca(int x,int y)
{
	if(x==y)return mp(-1,-1);
	int ff=0;
	if(dep[x]<dep[y])swap(x,y),ff=1;
	int X=x;
	for(int i=20;i>=0;i--)
	{
		if(dep[fa[x][i]]>=dep[y])x=fa[x][i];
	}
	if(x==y)
	{
		x=X;
		int D=dep[x]-dep[y]-1;
		//cout<<x<<" "<<D<<endl;
		for(int i=20;i>=0;i--)if(D>=(1<<i))D-=(1<<i),x=fa[x][i];
		if(ff)return mp(-1,x);
		else return mp(x,-1);
	}
	for(int i=20;i>=0;i--)
	{
		if(fa[x][i]!=fa[y][i])x=fa[x][i],y=fa[y][i];
	}
	if(ff)swap(x,y);
	return mp(x,y);
}
int cmp(node a,node b)
{
	if(dep[a.lca]!=dep[b.lca])return dep[a.lca]<dep[b.lca];
	if(a.lca!=b.lca)return a.lca<b.lca;
	if(a.a!=b.a)return a.a>b.a;
	return a.b>b.b;
}
signed main()
{
	n=read();tot=n;
	for(int i=1;i<n;i++)
	{
		int x=read(),y=read();
		add(x,y);add(y,x);
	}
	dfs(1,0);m=read();
	//cout<<"!!!"<<fa[3][0]<<endl;
	for(int i=1;i<=m;i++)
	{
		q[i].x=read();q[i].y=read();
		pair<int,int>tmp=lca(q[i].x,q[i].y);
		q[i].a=((tmp.first==-1)?(++tot):tmp.first);
		q[i].b=((tmp.second==-1)?(++tot):tmp.second);
		if(tmp.first!=-1&&tmp.second!=-1)q[i].lca=fa[tmp.first][0];
		else if(max(tmp.first,tmp.second)>0)q[i].lca=fa[max(tmp.first,tmp.second)][0];
		else q[i].lca=q[i].x;
		//cout<<"LCA="<<q[i].lca<<" "<<tmp.first<<" "<<tmp.second<<endl;;
		if(q[i].a>q[i].b)swap(q[i].a,q[i].b),swap(q[i].x,q[i].y);
	}
	sort(q+1,q+1+m,cmp);
	//for(int i=1;i<=m;i++)cout<<q[i].x<<" "<<q[i].y<<" "<<q[i].a<<" "<<q[i].b<<" "<<q[i].lca<<endl;
	//puts("");
	for(int i=1;i<=m;i++)
	{
		int j=i,sum=0;while(j<m&&q[j+1].lca==q[j].lca)j++;
		for(int k=i;k<=j;k++)
		{
			int L=k;while(L<j&&q[L+1].a==q[k].a)L++;
			for(int p=k;p<=L;p++)ans+=sum-b[q[p].b];
			for(int p=k;p<=L;p++)b[q[p].a]++,b[q[p].b]++;
			sum+=L-k+1;
			k=L;
		}
		for(int k=i;k<=j;k++)
		{
			ans+=t.query(rfn[q[k].lca])-t.query(dfn[q[k].lca]-1);
			//cout<<ans<<endl;
			if(q[k].a<=n)ans-=t.query(rfn[q[k].a])-t.query(dfn[q[k].a]-1);
			if(q[k].b<=n)ans-=t.query(rfn[q[k].b])-t.query(dfn[q[k].b]-1);
			//cout<<t.query(rfn[q[k].a])-t.query(dfn[q[k].a]-1)<<endl;
		}
		for(int k=i;k<=j;k++)t.modify(dfn[q[k].x],1),t.modify(dfn[q[k].y],1);
		i=j;
	}
	printf("%lld\n",ans);
}
