#include <bits/stdc++.h>
#define ll long long
#define loop(i, a, b) for(ll i=a;i<b;i++)
#define pool(i, a, b) for(ll i=a-1;i>=b;i--)
#define fore(i, a) for(auto&& i:a)
#define fi first
#define se second
#define ps(a) push_back(a)
#define pb(a) pop_back(a)
#define sc scanf
#define vc vector
#define lb lower_bound
#define ub upper_bound
#define all(a) a.begin(), a.end()
#define llmax LLONG_MAX/2
#define llmin -LLONG_MAX/2
using namespace std;
#define mn 300100
#define al 20
#define par pair<ll, ll>
#define ld long double
#define mod 1000000007
 
vc<ll> edg[mn];
 
ll tim=0, tin[mn], tout[mn], p[mn][al];
void dfs(ll u, ll per){
    tin[u]=tim++;
    
    p[u][0]=per;
    loop(i, 1, al) p[u][i]=p[p[u][i-1]][i-1];
    
    fore(v, edg[u]) if(v!=per) dfs(v, u);
    
    tout[u]=tim++;
}
 
ll isp(ll u, ll v){return tin[u]<=tin[v] && tout[v]<=tout[u];}
 
 
 
 
 
 
 
 
 
 
 
 
ll ans=0;ll n;
 
 
ll sing[mn], startup[mn], downup[mn], finsingall[mn], finduoall[mn];            
vc<ll> downuppos[mn], finsing[mn], duoposa[mn];
map<par, ll> finduo[mn];

void tour(ll u, ll per){
    fore(v, edg[u]) if(v!=per) tour(v, u);
    loop(i, 0, edg[u].size()) if(edg[u][i]!=per){
        ll v=edg[u][i];
        downuppos[u][i]=downup[v]+startup[v]-finsing[u][i];
    }
    
    fore(i, finduo[u]) finduoall[u]+=i.se, duoposa[u][i.fi.fi]+=i.se, duoposa[u][i.fi.se]+=i.se, downuppos[u][i.fi.fi]-=i.se, downuppos[u][i.fi.se]-=i.se;
    
    loop(i, 0, edg[u].size()) if(edg[u][i]!=per) downup[u]+=downuppos[u][i], finsingall[u]+=finsing[u][i];
    
    
    //sing
    ans+=sing[u] * (sing[u] - 1 + 2 * finduoall[u] + 2 * finsingall[u] + 2 * startup[u] + 2 * downup[u]);
    
    //duo
    //if(n!=300000){
    fore(i, finduo[u]){ ans+=i.se * ((finduoall[u] -duoposa[u][i.fi.fi] - duoposa[u][i.fi.se] +i.se)
                          + 2 * (finsingall[u] - finsing[u][i.fi.fi] - finsing[u][i.fi.se])
                          + 2 * (startup[u])
                          + 2 * (downup[u] - downuppos[u][i.fi.fi] - downuppos[u][i.fi.se]));
    }
    //finsing
    loop(i, 0, edg[u].size()) ans+=finsing[u][i] * (finsingall[u]-finsing[u][i]
                                 + 2 * startup[u]
                                 + 2 * (downup[u]-downuppos[u][i]));
    
}










ll getind(ll u, ll v){
    return lb(all(edg[u]), v)-edg[u].begin();
}
int main() {
    cin >> n;
    loop(i, 0, n-1){
        ll a, b;scanf("%lld%lld", &a, &b);
        edg[a].ps(b);
        edg[b].ps(a);
    }
    loop(i, 1, n+1) sort(all(edg[i])), downuppos[i].resize(edg[i].size()), finsing[i].resize(edg[i].size()), duoposa[i].resize(edg[i].size());
    dfs(1, 1);
    
    
    ll m;cin >> m;
    loop(i, 0, m){
        ll u, v;scanf("%lld%lld", &u, &v);
        if(u==v) sing[u]++;
        else if(isp(u, v) or isp(v, u)){
            if(isp(v, u)) swap(u, v); // u je višje
            
            startup[v]++;
            pool(j, al, 0) if (!isp(p[v][j], u)) v = p[v][j];
            finsing[u][getind(u, v)]++;
        }
        else{
            startup[v]++;startup[u]++;
            
            pool(j, al, 0) if (!isp(p[u][j], v)) u = p[u][j];
            pool(j, al, 0) if (!isp(p[v][j], u)) v = p[v][j];
            ll per=p[u][0];
            if(u>v) swap(u, v);
            finduo[per][make_pair(getind(per, u), getind(per, v))]++;
        }
    }
    tour(1, -1);
    cout << ans/2 << endl;
}