#include<bits/stdc++.h>

#define ll long long
#define rep(A,B,C) for(A=B;A<C;++A)
#define pii pair<int,int>
#define pll pair<ll,ll>

#define fi first
#define se second
#define all(A) A.begin(),A.end()

using namespace std;

/////////////////////////////////////////////////////
#define vv vector
#define Nmx 303030
#define lNmx 20

ll N,M;
vv<pll> uvv[Nmx + 3];
pll xyv[Nmx + 3];
ll dblp[Nmx + 3][lNmx + 3];
ll dps[Nmx + 3];
ll mked[Nmx + 3], mkcm[Nmx + 3];
vv<pll> cmv[Nmx + 3];
ll an[Nmx + 3];
ll i, j, k;


ll dfs1(ll a,ll p,ll d){
    
    dblp[a][0] = p;
    dps[a] = d;
    ll i = 0, pi = 0;
    ll c = 0;
    c += mked[a] - mkcm[a];
    rep(i,0,uvv[a].size()){
        ll b = uvv[a][i].fi;
        if(b==p){
            pi = i;
            continue;
        }
        ll rb= dfs1(b, a, d + 1);
        //printf("%lld,%lld,%lld\n", a, b, rb);
        uvv[a][i].se = rb;
        c += rb;
        //assert(false);
    }
    an[a] = c;
    uvv[a][pi].se = c - mkcm[a];
    //printf("%lld,%lld,%lld,%lld\n", a, p, d,uvv[1][0].se);
    return uvv[a][pi].se;
}

void dblinit(){
    ll i, j;
    rep(j,0,lNmx)
        rep(i,0,N+1)
            dblp[i][j + 1] = dblp[dblp[i][j]][j];
}

pll lcap(ll a,ll b){
    if(a==b)
        return {-1, -1};
    if(dps[a]<dps[b])
        swap(a, b);
    ll i = lNmx;
    while(dps[a]-dps[b]>1){
        if((1<<i)<=dps[a]-dps[b]-1)
            a = dblp[a][i];
        --i;
    }
    if(dps[a]>dps[b]){
        if(dblp[a][0]==b)
            return {a, -1};
        a = dblp[a][0];
    }
    i = lNmx;
    while(i>=0){
        if(dblp[a][i]!=dblp[b][i]){
            a = dblp[a][i];
            b = dblp[b][i];
        }
        --i;
    }
    if(a>b)
        swap(a, b);
    return {a, b};
}

ll calc(ll a){
    ll i;
    map<ll, ll> mp;
    rep(i,0,uvv[a].size()){
        mp[uvv[a][i].fi] = i;
    }
    ll ans = 0;
    map<pll, ll> mp2;
    rep(i,0,cmv[a].size()){
        
        ll aa = --an[a];
        ll p1 = cmv[a][i].fi, p2 = cmv[a][i].se;
        //printf("%lld:%lld,%lld,%lld,%lld ",a, i,p1,p2, an[a]);
        if(p1!=-1){
            ll I = mp[p1];
            aa -= --uvv[a][I].se;
            //printf("a%lld,", uvv[a][I].se);
        }
        if(p2!=-1){
            ll I = mp[p2];
            aa -= --uvv[a][I].se;
            //printf("b%lld,", uvv[a][I].se);
        }
        if(p1!=-1&&p2!=-1){
            //printf("c%lld,", mp2[cmv[a][i]]);
            aa += mp2[cmv[a][i]]++;
        }
        //printf("\n");
        ans += aa;
    }
    return ans;
}


void solve(){
    dfs1(1, 0, 1);
    dblinit();
    
    //assert(false);
    rep(i,0,M){
        pll xy = xyv[i];
        if(xy.fi>xy.se)
            swap(xy.fi, xy.se);
        ++mked[xy.fi];
        ++mked[xy.se];
        //printf("ccc%lld,%lld,\n", xy.fi, xy.se);
        if(xy.fi==xy.se){
            cmv[xy.fi].push_back({-1, -1});
            ++mkcm[xy.fi];
            continue;
        }
        pll cmp = lcap(xy.fi, xy.se);
        //printf("ddd%lld,%lld,%lld\n", cmp.fi, cmp.se,dblp[cmp.fi][0]);
        
        ll cm = dblp[cmp.fi][0];
        cmv[cm].push_back(cmp);
        ++mkcm[cm];
    }
    
    dfs1(1, 0, 1);
    /*rep(i,0,N+1){
        printf("\n%lld-%lld:\n", i, an[i]);
        rep(j,0,uvv[i].size()){
            printf("%lld,%lld\n", uvv[i][j].fi, uvv[i][j].se);
        }
    }*/
    ll ans=0;
    rep(i,0,N+1){
        ll a = calc(i);
        //printf("%lld,%lld\n", i, a);
        ans += a;
    }

    printf("%lld\n", ans);
}



int main(){
    scanf("%lld", &N);
    
    rep(i,1,N){
        ll u, v;
        scanf("%lld%lld", &u, &v);
        uvv[u].push_back({v, 0});
        uvv[v].push_back({u, 0});
    }
    uvv[1].push_back({0, 0});
    scanf("%lld", &M);
    rep(i,0,M){
        ll u, v;
        scanf("%lld%lld", &u, &v);
        xyv[i] = {u, v};
    }
    solve();

    return 0;
}