import sys input = sys.stdin.readline N,M=map(int,input().split()) # UnionFind Group = [i for i in range(N+1)] # グループ分け Nodes = [1]*(N+1) # 各グループのノードの数 def find(x): while Group[x] != x: x=Group[x] return x def Union(x,y): if find(x) != find(y): if Nodes[find(x)] < Nodes[find(y)]: Nodes[find(y)] += Nodes[find(x)] Nodes[find(x)] = 0 Group[find(x)] = find(y) else: Nodes[find(x)] += Nodes[find(y)] Nodes[find(y)] = 0 Group[find(y)] = find(x) BR=[list(map(int,input().split())) for i in range(M)] Q=int(input()) B=[] for i in range(Q): x=int(input()) B.append(x-1) SET=set(B) ANS=N*(N-1)//2 for i in range(M): if i in SET: pass else: if find(BR[i][0]) != find(BR[i][1]): x=Nodes[find(BR[i][0])] y=Nodes[find(BR[i][1])] ANS-=x*y Union(BR[i][0],BR[i][1]) LANS=[ANS] for x in B[::-1]: z,w=BR[x] if find(z)!=find(w): x0=Nodes[find(z)] y0=Nodes[find(w)] ANS-=x0*y0 Union(z,w) LANS.append(ANS) LANS.reverse() for x in LANS[1:]: print(x)