#include <bits/stdc++.h>
#define ll long long
#define fr first
#define sc second
#define mp make_pair
#define ii pair<ll,ll>
using namespace std;
int n,m;
vector < int > adj[400005];
int par[400005][30]; // initially all -1
int h[400005];
ll up[400005][3];
vector < ii > f[400005];
ll del_up[400005][3];
ll center[400005];
ll st[400005];
ll st2[400005];
void dfs(int v,int p = -1)
{
    par[v][0] = p;
    if(p + 1)
        h[v] = h[p] + 1;
    for(int i = 1; i < 30; i ++)
        if(par[v][i-1] + 1)
            par[v][i] = par[par[v][i-1]][i-1];
    for(int i=0; i<adj[v].size(); i++)
    {
        int u = adj[v][i];
        if(p - u)
            dfs(u,v);
    }
    return ;
}
int LCA(int v,int u)
{
    if(h[v] < h[u])
        swap(v,u);
    for(int i = 30 - 1; i >= 0; i --)
        if(par[v][i] + 1 and h[par[v][i]] >= h[u])
            v = par[v][i];
    // now h[v] = h[u]
    if(v == u)
        return v;
    for(int i = 30 - 1; i >= 0; i --)
        if(par[v][i] - par[u][i])
            v = par[v][i], u = par[u][i];
    return par[v][0];
}
int get_par_at(int node,int dis)
{
    int r = h[node]-dis;
    int v = node;
    for(int i = 30 - 1; i >= 0; i --)
        if(par[v][i] + 1 and h[par[v][i]] >= r)
            v = par[v][i];
    if(h[v] != r)
    {
        v = par[v][0];
    }

    return v;
}
ii get_last_par(int v,int u)
{
    int lc = LCA(v,u);
    ii res = mp(v,u);
    int dis1 = h[v]-h[lc]-1;
    int dis2 = h[u]-h[lc]-1;
    if(dis1 > 0)
    {
        res.fr = get_par_at(v,dis1);
    }
    if(dis2 > 0)
    {
        res.sc = get_par_at(u,dis2);
    }
    return res;
}
ll ans = 0;
ll ans2 = 0;
void dfs2(int node,int par)
{
    for(auto x : adj[node])
    {
        if(x != par)
        {
            dfs2(x,node);
        }
    }
    ll sum1 = 0 , sum2 = 0;
    for(auto x : adj[node])
    {
        if(x != par)
        {
            ans += (sum1 + sum2) * up[x][1];
            ans += (sum2) * (up[x][0]+del_up[x][0]);
            sum1 += up[x][0]+del_up[x][0];
            sum2 += up[x][1];
        }
    }
    for(auto x : f[node])
    {
        ll val1 = up[x.fr][1]+up[x.sc][1] + up[x.fr][0]+del_up[x.fr][0]+up[x.sc][0]+del_up[x.sc][0];
        ans += (sum1+sum2)- val1;
    }
    ll sz = f[node].size();
    ans += 1LL * (sum2+sz) * (st[node]);
    ans2 += 1LL * center[node] * (sum1 + sum2+sz+st[node]);
    if(center[node] > 0)
      ans2 += (center[node] * (center[node]-1))/2;
    if(par != -1)
    {
        up[par][0]+=up[node][0]+del_up[node][0];
    }
    return ;
}
int main()
{
    ios_base::sync_with_stdio(false);
    memset(par,-1,sizeof(par));
    cin>>n;
    for(int i=1; i<n; i++)
    {
        int x,y;
        cin>>x>>y;
        adj[x].push_back(y);
        adj[y].push_back(x);
    }
    int root = 1;
    dfs(root,-1);
    cin>>m;
    for(int i=0; i<m; i++)
    {
        int x,y;
        cin>>x>>y;
        if(x == y)
        {
            center[x]++;
        }
        else
        {
            int lc = LCA(x,y);
            if(lc == x)
            {
                ii A = get_last_par(x,y);
                int c = A.sc;
                up[y][0]++;
                del_up[c][0]--;
                up[c][1]++;
                st[y]++;
            }
            else if(lc == y)
            {
                swap(x,y);
                ii A = get_last_par(x,y);
                int c = A.sc;
                up[y][0]++;
                del_up[c][0]--;
                up[c][1]++;
                st[y]++;
            }
            else
            {
                ii A = get_last_par(x,y);
                up[x][0]++;
                up[y][0]++;
                del_up[A.fr][0]--;
                del_up[A.sc][0]--;
                st[x]++;
                st[y]++;
                f[lc].push_back(A);
            }
        }
    }
    for(int i=1; i<=n; i++)
    {
        map < int , int > my;
        map < ii , int > my2;
        int sz = f[i].size();
        ll old = 0;
        for(auto x : f[i])
        {
            ll r = old;
            r-= my[x.fr];
            r-= my[x.sc];
            r+= my2[x];
            ans += r;
            my[x.fr]++;
            my[x.sc]++;
            my2[x]++;
            my2[mp(x.sc,x.fr)]++;
            old++;
        }
        my.clear();
        my2.clear();
    }
    dfs2(root,-1);
    cout<<ans+ans2<<endl;
    return 0 ;
}
