# include using namespace std; typedef long long ll; # define int long long # define lc u << 1 # define rc u << 1 | 1 # define fi first # define se second const int N = 100005; int n, q; vector e[N]; int f[N][35], dep[N]; void dfs (int u, int fa) { f[u][0] = fa, dep[u] = dep[fa] + 1; for (int v : e[u]) { if (v == fa) continue; dfs (v, u); } } int getlca (int u, int v) { if (dep[u] < dep[v]) swap (u, v); for (int i = 30; i >= 0; i -- ) { if (dep[v] - dep[u] >= 1 << i) u = f[u][i]; } if (u == v) return u; for (int i = 30; i >= 0; i -- ) { if (f[u][i] != f[v][i]) u = f[u][i], v = f[v][i]; } return f[u][0]; } int cnt[N]; int ans; void dfs2 (int u, int fa) { for (int v : e[u]) { if (v == fa) continue; dfs2 (v, u); } cnt[fa] += cnt[u]; ans += cnt[u] * (cnt[u] + 1) / 2; } signed main () { // freopen ("tax.in", "r", stdin); freopen ("tax.out", "w", stdout); scanf ("%lld", &n); for (int i = 1; i < n; i ++ ) { int u, v; scanf ("%lld%lld", &u, &v); u --, v -- ; e[u].push_back (v), e[v].push_back (u); } dfs (0, -1); for (int j = 1; j <= 30; j ++ ) { for (int i = 0; i < n; i ++ ) f[i][j] = f[f[i][j - 1]][j - 1]; } scanf ("%lld", &q); while (q -- ) { int u, v; scanf ("%lld%lld", &u, &v); u --, v -- ; int lca = getlca (u, v); cnt[u] ++ , cnt[v] ++ , cnt[lca] -- , cnt[f[lca][0]] -- ; } dfs2 (0, -1); printf ("%lld\n", ans); return 0; }