# include using namespace std; typedef long long ll; const int N = 100010; struct edge {ll to, next;} e[N << 1]; ll n, q, ans; ll cnt, head[N]; ll dep[N], d[N]; ll f[N][22]; void add(ll u, ll v) {e[++cnt] = {v, head[u]}, head[u] = cnt;} void DFS(ll u, ll fa) { dep[u] = dep[fa] + 1; f[u][0] = fa; for (int i = 1; (1 << i) <= dep[u]; i++) f[u][i] = f[f[u][i - 1]][i - 1]; ll v; for (int i = head[u]; i; i = e[i].next) { v = e[i].to; if (v == fa) continue; DFS(v, u); } } ll DFS2(ll u, ll fa) { ll v; for (int i = head[u]; i; i = e[i].next) { v = e[i].to; if (v == fa) continue; d[u] += DFS2(v, u); } ans += (d[u] + 1) * d[u] / 2; return d[u]; } ll LCA(ll u, ll v) { if (dep[u] < dep[v]) swap(u, v); ll txp; txp = dep[u] - dep[v]; for (int i = 21; i >= 0; i--) if (txp & (1 << i)) u = f[u][i]; if (u == v) return u; for (int i = 21; i >= 0; i--) if (f[u][i] != f[v][i]) u = f[u][i], v = f[v][i]; return f[u][0]; } int main() { scanf("%lld", &n); for (int i = 1; i < n; i++) { ll u, v; scanf("%lld%lld", &u, &v); add(u, v), add(v, u); } DFS(1, 0); scanf("%lld", &q); while (q--) { ll a, b, lca; scanf("%lld%lld", &a, &b); lca = LCA(a, b); d[a]++, d[b]++; d[lca]--; if (f[lca][0] >= 0) d[f[lca][0]]--; } ans = 0; DFS2(1, 0); printf("%lld\n", ans); return 0; }