#include using namespace std; #define ALL(x) (x).begin(),(x).end() #define REP(i, n) for(ll i=0; i<(ll)(n); i++) #define PER(i, n) for(ll i=(ll)(n)-1; i>=0; i--) template int LB(const vector& v, T x) { return lower_bound(ALL(v),x)-v.begin(); } template int UQ(T& v) { sort(ALL(v)); v.erase(unique(ALL(v)),v.end()); return v.size(); } template bool chmax(T &a, T b) { return a bool chmin(T &a, T b) { return a>b ? a=b, true : false; } template using rpriority_queue = priority_queue,greater>; using ll=long long; const int INF=1e9+10; const ll INFL=4e18; using ld=long double; using lll=__int128_t; using ull=unsigned long long; using VI=vector; using VVI=vector; using VL=vector; using VVL=vector; using PL=pair; using VP=vector; using WG=vector>>; #ifdef LOCAL #include "./debug.hpp" #else #define debug(...) #define print_line #endif /// @brief Disjoint Set Union struct DSU { DSU()=default; DSU(int n) { par.resize(n); iota(par.begin(),par.end(),0); sz=vector(n,1); forest_count=n; } int find(int x) { if(par[x]==x) return x; return par[x]=find(par[x]); } bool merge(int x, int y) { x=find(x); y=find(y); if(x==y) return false; if(sz[x]> groups() { int n=par.size(); vector> ret(n); for(int i=0; i& v) { return v.empty(); }),ret.end()); return ret; } private: vector par,sz; int forest_count; }; //---------------------------------------------------------- void solve() { ll N,M; cin>>N>>M; VP E(M); for(auto& [a,b]: E) cin>>a>>b, a--, b--; VI aru(M,1); int Q; cin>>Q; VI qry(Q); REP(i,Q) cin>>qry[i], qry[i]--, aru[qry[i]]=0; DSU dsu(N); ll tmp=N*(N-1)/2; REP(i,M) if(aru[i]) { auto [u,v]=E[i]; if(!dsu.same(u,v)) tmp-=(ll)dsu.size(u)*dsu.size(v); dsu.merge(u,v); } VL ans(Q); PER(i,Q) { ans[i]=tmp; auto [u,v]=E[qry[i]]; if(!dsu.same(u,v)) tmp-=(ll)dsu.size(u)*dsu.size(v); dsu.merge(u,v); } REP(i,Q) cout<>T; while(T--) solve(); }