#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <vector>
#include <queue>
#include <map>
#include <set>
using namespace std;
#define ll long long
#define ull unsigned long long
#define fi first
#define se second
#define dingyi int mid = l + r >> 1, ls = p << 1, rs = p << 1 | 1
#define y0 y_csyakioi_0
#define y1 y_csyakioi_1
#define rep(i, x, y) for(int i = x; i <= y; ++i)
#define per(i, x, y) for(int i = x; i >= y; --i)
#define repg(i, u) for(int i = head[u]; i; i = e[i].nxt)
inline 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 * 10 + (ch ^ 48); ch = getchar(); }
	return x * f;
}
const int N = 300010;
struct edge{ int v, nxt; }e[N << 1]; struct pat{ int x, y, z, a, b; }q[N];
int head[N], cnt, n, m, x, y, z, L[N], R[N], tot, num, f[N][20], g[N << 2], c[N], dep[N];
inline void add(int u, int v){ e[++cnt].v = v; e[cnt].nxt = head[u]; head[u] = cnt; }
inline void dfs(int u, int fa){
	f[u][0] = fa; L[u] = ++tot; dep[u] = dep[fa] + 1;
	rep(i, 1, 19) f[u][i] = f[f[u][i - 1]][i - 1];
	repg(i, u) if(e[i].v != fa) dfs(e[i].v, u); R[u] = tot;
}
inline int lca(int x, int y){
	if(dep[x] < dep[y]) swap(x, y); per(i, 19, 0) if(dep[f[x][i]] >= dep[y]) x = f[x][i];
	if(x == y) return x; per(i, 19, 0) if(f[x][i] != f[y][i]) x = f[x][i], y = f[y][i];
	return f[x][0];
}
inline int lb(int x){ return x & -x; }
inline void change(int x, int y){ for(; x <= n; x += lb(x)) c[x] += y; }
inline int query(int x){ int ans = 0; for(; x; x -= lb(x)) ans += c[x]; return ans; }
inline int Query(int l, int r){ return query(r) - query(l - 1); }
inline int anc(int x, int y){ if(x == y) return ++num; per(i, 19, 0) if(dep[f[x][i]] > dep[y]) x = f[x][i]; return x; }
inline bool cmp(pat x, pat y){ return dep[x.z] ^ dep[y.z] ? dep[x.z] < dep[y.z] : x.z ^ y.z ? x.z < y.z : x.a ^ y.a ? x.a > y.a : x.b > y.b; }
inline void mian(){
	num = n = read(); rep(i, 1, n - 1) x = read(), y = read(), add(x, y), add(y, x); dfs(1, 0);
	m = read(); rep(i, 1, m){
		x = q[i].x = read(); y = q[i].y = read(); z = q[i].z = lca(x, y); q[i].a = anc(x, z); q[i].b = anc(y, z);
		if(q[i].a > q[i].b) swap(q[i].x, q[i].y), swap(q[i].a, q[i].b);
	}
	sort(q + 1, q + m + 1, cmp); ll ans = 0;
	rep(i, 1, m){
		int j = i; for(; j < m && q[j + 1].z == q[i].z; ++j); int sum = 0;
		rep(k, i, j){
			int l = k; for(; l < j && q[l + 1].a == q[k].a; ++l);
			rep(p, k, l) ans += sum - g[q[p].b];
			rep(p, k, l) ++g[q[p].a], ++g[q[p].b];
			sum += l - k + 1; k = l;
		}
		rep(k, i, j) g[q[k].a] = g[q[k].b] = 0;
		rep(k, i, j){
			ans += Query(L[q[k].z], R[q[k].z]);
			if(q[k].a <= n) ans -= Query(L[q[k].a], R[q[k].a]);
			if(q[k].b <= n) ans -= Query(L[q[k].b], R[q[k].b]);
		}
		rep(k, i, j) change(L[q[k].x], 1), change(L[q[k].y], 1); i = j;
	}
	printf("%lld", ans);
}
int main(){ int qwq = 1; while(qwq--) mian(); return 0; }