//In the name of Allah
#include <bits/stdc++.h>
using namespace std;

const int N = 3e5 + 7, L = 20;
long long n, m, h[N], cnt[N], dp[N], par[N][L], ans, start[N];
map <pair <int, int>, long long> mp[N];
vector <int> adj[N];

void dfs_build(int u = 1) {
	for (int i = 1; i < L; i++)
		par[u][i] = par[par[u][i - 1]][i - 1];
	for (int v: adj[u])
		if (v != par[u][0]) {
			par[v][0] = u;
			h[v] = h[u] + 1;
			dfs_build(v);
		}
}

tuple <int, int, int> lca(int u, int v) {
	if (h[u] != h[v]) {
		for (int i = 0, len = h[u] - h[v] - 1; i < L; i++)
			if (1 << i & len)
				u = par[u][i];
		if (par[u][0] == v)
			return {v, u, u};
		u = par[u][0];
	}
	for (int i = L - 1; i >= 0; i--)
		if (par[u][i] != par[v][i]) {
			u = par[u][i];
			v = par[v][i];
		}
	if (u > v)
		swap(u, v);
	return {par[u][0], u, v};
}

void dfs_get_ans(int u = 1) {
	for (int v: adj[u])
		if (v != par[u][0])
			dfs_get_ans(v);
	map <int, long long> t;
	long long sum = 0, tmp = 0;
	for (auto [p, val]: mp[u]) {
		auto [x, y] = p;
		sum += val;
		t[x] += val;
		if (x != y)
			t[y] += val;
	}
	for (auto [p, val]: mp[u]) {
		auto [x, y] = p;
		if (x != y)
			tmp += val * (sum - t[x] - t[y] + val);
		else
			tmp += val * (sum - t[x]);
	}
	for (int v: adj[u])
		if (v != par[u][0]) {
			ans += (dp[v] - t[v]) * (sum - t[v]);
			dp[u] += dp[v];
		}
	ans += tmp / 2 + cnt[u] * (cnt[u] - 1) / 2  + cnt[u] * (sum + dp[u]) + start[u] * sum;
}

int main() {
	ios_base::sync_with_stdio(0), cin.tie(0);
	cin >> n;
	for (int i = 0, u, v; i < n - 1; i++) {
		cin >> u >> v;
		adj[u].push_back(v);
		adj[v].push_back(u);
	}
	dfs_build();
	cin >> m;
	for (int i = 0, u, v; i < m; i++) {
		cin >> u >> v;
		if (u == v) {
			cnt[u]++;
			continue;
		}
		if (h[u] < h[v])
			swap(u, v);
		auto [x, y, z] = lca(u, v);
		dp[u]++;
		dp[v]++;
		dp[x] -= 2;
		mp[x][{y, z}]++;
		start[u]++;
		if (x != v)
			start[v]++;
	}
	dfs_get_ans();
	cout << ans << endl;
}