class UnionFind: def __init__(self, n): self.par = [-1] * n self.res = n * (n - 1) // 2 def find(self, x): if self.par[x] < 0: return x self.par[x] = self.find(self.par[x]) return self.par[x] def union(self, x, y): x, y = self.find(x), self.find(y) if x == y: return if self.par[x] > self.par[y]: x, y = y, x self.res -= self.par[x] * self.par[y] self.par[x] += self.par[y] self.par[y] = x N, M = map(int, input().split()) edges = [tuple(map(int, input().split())) for _ in range(M)] Q = int(input()) B = [int(input()) for _ in range(Q)] BS = set(B) uf = UnionFind(N) for i, (u, v) in enumerate(edges, 1): if i not in BS: uf.union(u - 1, v - 1) ans = [] for b in B[::-1]: ans.append(uf.res) u, v = edges[b - 1] uf.union(u - 1, v - 1) print(*ans[::-1], sep='\n')