You are given a tree consisting of n vertices, and m simple vertex paths. Your task is to find how many pairs of those paths intersect at exactly one vertex. More formally you have to find the number of pairs (i, j) (1 ≤ i < j ≤ m) such that path_i and path_j have exactly one vertex in common. 

Input

First line contains a single integer n (1 ≤ n ≤ 3 ⋅ 10^5).

Next n - 1 lines describe the tree. Each line contains two integers u and v (1 ≤ u, v ≤ n) describing an edge between vertices u and v.

Next line contains a single integer m (1 ≤ m ≤ 3 ⋅ 10^5).

Next m lines describe paths. Each line describes a path by it's two endpoints u and v (1 ≤ u, v ≤ n). The given path is all the vertices on the shortest path from u to v (including u and v).

Output

Output a single integer — the number of pairs of paths that intersect at exactly one vertex.

Examples

Input


5
1 2
1 3
1 4
3 5
4
2 3
2 4
3 4
3 5


Output


2


Input


1
3
1 1
1 1
1 1


Output


3


Input


5
1 2
1 3
1 4
3 5
6
2 3
2 4
3 4
3 5
1 1
1 2


Output


7

Note

<image>

The tree in the first example and paths look like this. Pairs (1,4) and (3,4) intersect at one vertex.

In the second example all three paths contain the same single vertex, so all pairs (1, 2), (1, 3) and (2, 3) intersect at one vertex.

The third example is the same as the first example with two additional paths. Pairs (1,4), (1,5), (2,5), (3,4), (3,5), (3,6) and (5,6) intersect at one vertex.
#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;
}