#include<vector>
#include<cstdio>
using namespace std;
vector<int> g[202];
bool ex[202];
int main() {
int N, M, K;
scanf("%d %d", &N, &M);
int a, b;
for (int i = 0; i < M; i++) {
scanf("%d %d", &a, &b);
g[a].push_back(b);
g[b].push_back(a);
}
scanf("%d", &K);
while(K--) {
int vn;
vector<int> test;
scanf("%d", &vn);
for (int i = 0; i < vn; i++) {
scanf("%d", &a);
test.push_back(a);
}
bool yes = true;
if (vn < N + 1) {
printf("NO\n");
continue;
}
for (int i = 1; i <= N; i++) {
ex[i] = false;
}
for (int i = 0; i < vn - 1; i++) {
int temp = test[i];
if (ex[temp] == true) {
yes = false;
break;
}
else ex[temp] = true;
int j;
for (j = 0; j < g[temp].size(); j++) {
if (g[temp][j] == test[i + 1]) break;
}
if (j == g[temp].size()) {
yes = false;
break;
}
}
if (test[0] != test[vn - 1]) yes = false;
if (yes) printf("YES\n");
else printf("NO\n");
}
return 0;
}