#include <string.h>
#include <assert.h>
#include <cassert>
#include <unordered_map>
#include <unordered_set>
#include <time.h>

#include <sstream>
#include <stdio.h>
#include <assert.h>
#include <math.h>
#include <bitset>
#include <algorithm>
#include <iostream>
#include <stack>
#include <queue>
#include <set>
 
#include <map>
#include <vector>
#include <string>
#include <stdlib.h>
#include <cassert>
//#include<bits/stdc++.h>

 
#define ll long long
#define ull unsigned long long
#define clr(x) memset(x,0,sizeof(x))
#define _clr(x) memset(x,-1,sizeof(x))
#define fr(i,a,b) for(int i = a; i < b; ++i)
#define frr(i,a,b) for(int i = a; i > b; --i)
#define pb push_back
#define sf scanf
 
#define pf printf
#define mp make_pair
#define pir pair<int,int>
//#define N 2e5+10
#define N 400100
 
using namespace std;
//int mod = 998244353;
int mod = 1e9+7;

int get_min(int a, int b){
	if(a==-1) return b;
	if(b==-1) return a;
	return min(a,b);
}

vector<int> g[N];
int dep[N],fa[N][20],dfn[N],in[N],out[N];
int la[N];
int a[N],b[N],pa[N],pb[N];
int idx;

void dfs(int t, int f){
	dep[t] = dep[f]+1;
	in[t] = idx;
	dfn[idx++]=t;
	fa[t][0] = f;
	for(int i = 1; i <20; ++i){
		fa[t][i] = fa[fa[t][i-1]][i-1];
	}
	for(int u : g[t]){
		if(u==f)continue;
		dfs(u,t);
	}
	out[t] = idx-1;
}

int lca(int a, int b){
	if(dep[a]<dep[b])swap(a,b);
	for(int i = 19;i>=0;--i){
		if(dep[fa[a][i]]>=dep[b]) a = fa[a][i];
	}
	if(a==b) return a;
	for(int i = 19; i >=0;--i){
		if(fa[a][i] != fa[b][i]) {
			a = fa[a][i];
			b = fa[b][i];
		}
	}
	return fa[a][0];
}

int sum[N];
void add(int v){
	for(; v <=idx; v += v&-v){
		sum[v]++;
	}
}

int get1(int v){
	int ret = 0;
	while(v>0){
		ret += sum[v];
		v-=v&-v;
	}
	return ret;
}

int get(int v){
	if(v==-1) return 0;
	return get1(out[v]) - get1(in[v]-1);
}

int get_a(int f, int v){
	if(v==f)return -1;
	for(int i = 19;i >=0;--i){
		if(dep[fa[v][i]] >=dep[f]+1){
			v = fa[v][i];
		}
	}
	return v;
}

int main(){
	int n,m;
	cin>>n;
	fr(i,0,n-1){
		int u,v;
		sf("%d%d",&u,&v);
		g[u].pb(v);
		g[v].pb(u);
	}

	idx = 1;
	dfs(1,1);

	cin>>m;
	vector<int> pos;
	fr(i,0,m){
		sf("%d%d",&a[i],&b[i]);
		if(dep[a[i]] > dep[b[i]]){
			swap(a[i],b[i]);
		}
		else if(dep[a[i]] == dep[b[i]]){
			if(in[a[i]] > in[b[i]]){
				swap(a[i],b[i]);
			}
		}
		la[i] = lca(a[i],b[i]);
		pa[i] = get_a(la[i],a[i]);	
		pb[i] = get_a(la[i],b[i]);	
		pos.pb(i);
	}

	auto cmp = [&](int i, int j){
		return dep[la[i]]<dep[la[j]];
	};
	sort(pos.begin(), pos.end(), cmp);

	int last = 0;
	ll ans = 0;
	for(int i = 0; i < pos.size();++i){
		while(last<pos.size() && dep[la[pos[last]]] < dep[la[pos[i]]]){
			int idx = pos[last++];
			add(in[a[idx]]);
			add(in[b[idx]]);
		}
		int idx = pos[i];
		int tot = get(la[idx]);
		int ask = get(pa[idx]);
		ask += get(pb[idx]);
		ans += tot - ask;
	}

	map<int, vector<pair<int,int> >> p;
	for(int i = 0; i < pos.size();++i){
		int idx = pos[i];
		int pa = get_a(la[idx],a[idx]);	
		int pb = get_a(la[idx],b[idx]);	
		if(pa>pb)swap(pa,pb);
		p[la[idx]].pb(mp(pa,pb));
	}

	ll ans2 = 0;
	for(auto it : p){
		map<int,int> ft;
		map<pair<int,int>,int > ftt;
		auto&vec = it.second;
		
		ll tot = 0;
		for(auto x : vec) {
			if(x.first>=0)
				ft[x.first]++;
			if(x.second>=0)
				ft[x.second]++;
			if(x.first>=0&&x.second>=0)
				ftt[x]++;
			tot++;
		}

		for(auto x : vec) {
			ans2 += tot - ft[x.first] - ft[x.second] + ftt[x];
			if(x.first==-1&&x.second==-1)ans2--;
			//printf("lca = %d tot = %d x.first = %d ft = %d x.second = %d ft = %d ftt = %d ans2 = %d\n",it.first, tot,x.first, ft[x.first], x.second, ft[x.second], ftt[x], ans2);

		}
	}

	cout<<ans+ans2/2<<endl;
}

