#include <iostream>
#include <vector>
#include <map>
#include <algorithm>
using namespace std;
bool e[201][201];
int main(){
int n, m;
cin >> n >> m;
for (int i = 0; i < m; i++) {
int a, b;
cin >> a >> b;
e[a][b] = e[b][a] = 1;
}
int k;
cin >> k;
for (int i = 0; i < k; i++) {
int c, flag = 1;
cin >> c;
vector<int> temp(c), visited(c, 0);
for (int j = 0; j < c; j++) cin >> temp[j];
if(c != n + 1 || temp[0] != temp[c-1]) flag = 0;
if (flag) {
for (int i = 0; i < c - 1; i++) {
visited[temp[i]]++;
}
for (int i = 1; i < c; i++) {
if(visited[i] != 1) {flag = 0; break;}
}
}
if(flag) cout << "YES\n";
else cout << "NO\n";
}
return 0;
}