#include using namespace std; #define INF 1000000000 #define REP(i,n) for(int (i)=0;(i)<(int)(n);(i)++) typedef long long int LL; int parent[100002]; int rnk[100002]; vector v[100002]; int cost[100002]; bool check[100002]; bool check2[100002]; //親の作成 void dfs(int n,int x){ REP(i,v[n].size()){ int a=v[n][i]; if(check[a]==false){ check[a]=true; parent[a]=n; rnk[a]=x; dfs(a,x+1); } } } //imos法 LL imos(int n,LL *m){ LL ans=0; LL sum=0; LL pre=*m; REP(i,v[n].size()){ int a=v[n][i]; if(check2[a]==false){ check2[a]=true; ans+=imos(a,m); sum+=*m-pre; *m=pre; } } *m=*m+sum; LL mm=*m; mm+=cost[n]; ans+=(mm+1)*mm/2; *m=mm; //cout<>N; REP(i,N-1){ int a,b; cin>>a>>b; v[a].push_back(b); v[b].push_back(a); } check[1]=true; rnk[1]=0; dfs(1,1); cin>>Q; REP(i,Q){ int a,b; cin>>a>>b; cost[a]++; cost[b]++; if(lca(a,b)!=-1){ cost[lca(a,b)]--; if(parent[lca(a,b)]!=-1){ cost[parent[lca(a,b)]]--; } } } check2[1]=true; LL *m; LL ans=imos(1,m); cout<