#include using namespace std; typedef long long LL; typedef vector V; typedef vector Graph; #define PB push_back struct INIT{INIT(){ios::sync_with_stdio(false);cin.tie(0);}}init; void make_tree(int v,Graph& G,V& Par,V& D, Graph& C){ for(auto &e:G[v]){ if(e!=Par[v]){ C[v].PB(e); D[e]=D[v]+1; Par[e]=v; make_tree(e,G,Par,D,C); } } } //lcaの準備 void build_PP(V& P,vector& PP){ int N = P.size(); for(int i = 0; i < N; i++)PP[0][i] = P[i]; for(int k = 0,f=1;f; k++){ f=0; for(int i = 0; i < N; i++){ if(PP[k][i]<0)PP[k+1][i]=-1; else {PP[k+1][i]=PP[k][PP[k][i]];f=1;} } } } int lca(int u,int v,V& D,vector &PP){ if(D[u] > D[v])swap(u,v); for(int k = 0,d;(d=D[v]-D[u]); k++)if((d >> k) & 1)v=PP[k][v]; if(u==v)return v; for(int k = PP.size() - 1; k >=0 ; k--){ if(PP[k][u]!=PP[k][v]){ u=PP[k][u]; v=PP[k][v]; } } return PP[0][u]; } LL dfs(int v,vector& val,Graph &C){ LL res=0; for(auto &u:C[v]){ res+=dfs(u,val,C); val[v]+=val[u]; } return res+val[v]*(val[v]+1)/2; } int main(){ int N; cin>>N; Graph g(N+1),child(N+1); V depth(N+1,0),par(N+1,-1); vector parpar(20,V(N+1,-1)); vector val(N+1,0); g[0].push_back(1); for(int i=1;i>u>>v; g[u].push_back(v); g[v].push_back(u); } make_tree(0,g,par,depth,child); build_PP(par,parpar); int Q; cin>>Q; while(Q--){ int a,b; cin>>a>>b; int ca=lca(a,b,depth,parpar); int cp=par[ca]; val[a]++,val[b]++,val[ca]--,val[cp]--; } cout<