#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int N = 10010, M = N * 2;
vector<int> g[N];
int main() {
int n, m;
cin >> n >> m;
for (int i = 0; i < m; i++) {
int a, b;
cin >> a >> b;
g[a].push_back(b), g[b].push_back(a);
}
int q;
cin >> q;
while (q--) {
int k;
cin >> k;
set<int> destory;
for (int i = 0; i < k; i++) {
int x;
cin >> x;
destory.insert(x);
}
vector<bool> vis(n + 1, false);
function<void(int)> dfs = [&](int u) {
vis[u] = true;
for (auto &v : g[u]) {
if (vis[v] || destory.count(v)) continue;
dfs(v);
}
};
int res = 0;
for (int i = 1; i <= n; i++) {
if (!vis[i] && !destory.count(i)) {
res++;
dfs(i);
}
}
if (res == n - k) cout << "YES" << "\n";
else cout << "NO" << "\n";
}
return 0;
}