#include using namespace std; constexpr int nax = 1e5, eax = 1e5, pax = 1e5; int n, e, p, t, deg[nax + 1], fu[nax + 1]; bool vis[nax + 1]; vector< int > gr[nax + 1]; vector< int > ch[nax + 1]; queue< int > Q; int find(const int v) { return (fu[v] < 0? v : fu[v] = find(fu[v])); } bool join(int p, int q) { p = find(p), q = find(q); if (p == q) return false; if (fu[p] > fu[q]) swap(p, q); fu[p] += fu[q]; fu[q] = p; return true; } int main() { ios::sync_with_stdio(false); cin.tie(nullptr); cin >> n >> e >> p; for (int i = 0; i < e; ++i) { int p, q; cin >> p >> q; gr[p].push_back(q); gr[q].push_back(p); ++deg[p], ++deg[q]; } t = sqrt(e) + 1; for (int i = 1; i <= n; ++i) if (deg[i] <= t) Q.push(i); while (not Q.empty()) { int v = Q.front(); Q.pop(); vis[v] = true; for (int s : gr[v]) if (not vis[s]) { ch[v].push_back(s); if (deg[s] > t and --deg[s] <= t) Q.push(s); } } for (int i = 0; i < p; ++i) { int k; cin >> k; vector< int > tab(k); for (int& v : tab) cin >> v; for (int v : tab) fu[v] = -1; int res = tab.size(); for (int v : tab) for (int s : ch[v]) if (fu[s]) res -= join(v, s); for (int v : tab) fu[v] = 0; cout << res << '\n'; } }