class dsu(): n=1 parent_or_size=[-1 for i in range(n)] def __init__(self,N): self.n=N self.parent_or_size=[-1 for i in range(N)] def merge(self,a,b): assert 0<=a0: result2.append(result[i]) return result2 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)