#include <bits/stdc++.h>
using namespace std;


//#define int long long 


namespace tree{
    vector <vector <int> > adj, par;
    vector <int> st, en, lvl;
    int k, t = 0;

    void init(int n) {
        k = 32 - __builtin_clz(n);
        par = vector <vector <int> > (k, vector <int> (n + 1));
        adj = vector <vector <int> > (n + 1);
        st = en = lvl = vector <int> (n + 1);
    }

    void add_edge(int u, int v) {
        adj[u].push_back(v);
        adj[v].push_back(u);
    }

    void dfs(int v,int p) {
        par[0][v] = p;
        for(int i = 1; i < k; i++) 
           par[i][v] = par[i - 1][par[i - 1][v]];

        st[v] = ++t;
        lvl[v] = lvl[p] + 1;

        for(int u: adj[v]) 
            if(p ^ u) 
                dfs(u, v);
        
        en[v] = ++t;
    }

    int lift(int v, int dis) {
        for(int i = k - 1; i >= 0; i--)
            if(lvl[v] - (1 << i) >= dis)
                v = par[i][v];
        return v;
    }

    int lca(int u, int v) {
        if(lvl[u] > lvl[v]) 
            swap(u, v);

        v = lift(v, lvl[u]);

        for(int i = k - 1; i >= 0; i--) 
            if(par[i][v] ^ par[i][u]) 
                u = par[i][u], 
                v = par[i][v];
        
        return u == v ? v : par[0][v];
    }
}


const int N = 3e5 + 7;

vector <pair <int, int> > a[N];

vector <int> b[N]; 

int C[N];

struct bit{
    int n, s, i; vector <int> t;
    bit(int n) : n(n), t(n + 1, 0) { 
    }
    void modify(int r, int v) {
        for(i = r; i <= n; i += i & -i) t[i] += v;
    }
    int sum(int r) {
        for(s = 0; r >= 1; r -= r & -r) s += t[r];
        return s;
    }
    int sum(int l, int r) {
        assert(l <= r);
        return sum(r) - sum(l - 1);
    }
};

int64_t dfs(int v, int p, bit &A, bit &B) {
    int64_t ans = 0;

    B.modify(tree::lvl[v], +C[v]);
    for(auto [px, qx]: a[v]) {
        A.modify(tree::lvl[v], +1);
        if(px ^ v)
            C[px]++;
        if(qx ^ v)
            C[qx]++;
    }

    for(int u: b[v]) {
        ans += A.sum(tree::lvl[u] + 1, tree::lvl[v]);
        if(tree::lvl[u] + 2 <= tree::lvl[v])
            ans -= B.sum(tree::lvl[u] + 2, tree::lvl[v]); 
    }


    for(int u: tree::adj[v]) if(u ^ p) {
        ans += dfs(u, v, A, B);
    }

    B.modify(tree::lvl[v], -C[v]);
    for(auto [px, qx]: a[v]) {
        A.modify(tree::lvl[v], -1);
    }


    return ans;
}


int32_t main() {
    ios_base :: sync_with_stdio(0); cin.tie(0); cout.tie(0);
    int n, m; cin >> n;


    bit A(n + 10), B(n + 10);

    tree::init(n);
    for(int i = 1; i < n; i++) {
        int u, v; cin >> u >> v;
        tree::add_edge(u, v);
    }


    tree::dfs(1, 0);
    cin >> m;
    for(int i = 1; i <= m; i++) {
        int u, v; cin >> u >> v;
        int p = tree::lca(u, v);
        if(u ^ p)
            b[u].push_back(p);
        if(v ^ p)
            b[v].push_back(p);
        int ux = tree::lift(u, tree::lvl[p] + 1);
        int vx = tree::lift(v, tree::lvl[p] + 1);
        a[p].push_back(make_pair(ux, vx));
    }

    cout << endl;

    int64_t ans = 0;

    for(int i = 1; i <= n; i++) {
        map <pair <int, int>, int> mp;
        map <int, int> c;
        int cnt = 0;
        for(auto [u, v]: a[i]) {
            ans += cnt;
            if(c.count(u)) ans -= c[u];
            if(c.count(v)) ans -= c[v];
            if(u > v) swap(u, v);
            if(mp.count(make_pair(u, v))) 
                ans += mp[make_pair(u, v)];

            if(u != i) c[u]++;
            if(v != i) c[v]++;
            if(u != i && v != i)
                mp[make_pair(u, v)]++;
            ++cnt;
        } 
    }

    

    cout <<  ans + dfs(1, 0, A, B) << endl;
}