from atcoder.dsu import DSU n,m=map(int,input().split()) edge=[list(map(int,input().split())) for _ in range(m)] q=int(input()) Q=[int(input())-1 for _ in range(q)] QS=set(Q) G=DSU(n) for i in range(m): if i not in QS: a,b=edge[i] a-=1 b-=1 G.merge(a,b) UF=G.groups() tmp=0 for e in UF: tmp+=(n-len(e))*len(e) cnt=tmp//2 ans=[] for i in Q[::-1]: ans.append(cnt) a,b=edge[i] a-=1 b-=1 if G.same(a,b): pass else: A=G.size(a) B=G.size(b) cnt-=A*B G.merge(a,b) for e in ans[::-1]: print(e)