#include using namespace std; using ll = long long; #define rep(i, s, t) for (ll i = s; i < (ll)(t); i++) #define all(x) begin(x), end(x) template bool chmin(T& x, T y) { return x > y ? (x = y, true) : false; } template bool chmax(T& x, T y) { return x < y ? (x = y, true) : false; } struct io_setup { io_setup() { ios::sync_with_stdio(false); std::cin.tie(nullptr); cout << fixed << setprecision(15); } } io_setup; #include void solve() { int n, m; cin >> n >> m; vector u(m), v(m); rep(i, 0, m) cin >> u[i] >> v[i], u[i]--, v[i]--; int q; cin >> q; vector b(q); rep(i, 0, q) cin >> b[i], b[i]--; atcoder::dsu uf(n); ll tmp = 0; { set st(b.begin(), b.end()); rep(i, 0, m) if (!st.count(i)) { uf.merge(v[i], u[i]); } auto vv = uf.groups(); for (auto x : vv) { tmp += (ll)x.size() * (n - x.size()); } } tmp /= 2; vector ans; reverse(b.begin(), b.end()); for (int bi : b) { ans.push_back(tmp); int lu = uf.leader(u[bi]); int lv = uf.leader(v[bi]); if (lu == lv) continue; tmp -= (ll)uf.size(lu) * uf.size(lv); uf.merge(lu, lv); } reverse(ans.begin(), ans.end()); for (auto x : ans) cout << x << "\n"; } int main() { int t = 1; // cin >> t; while (t--) solve(); }