#include <iostream>
#include <cstring>
#include <algorithm>
#include <unordered_set>
#include <vector>
using namespace std;
const int N = 1e5+10;
int h[N],e[N],ne[N],idx;
void add(int a,int b)
{
e[idx] = b,ne[idx] = h[a],h[a] = idx++;
}
int n,m;
int k,del,l;
bool st[N];
unordered_set<int>stk;
bool dfs()
{
for(int p = 1;p <= n;p++)
{
if(!stk.count(p)&&st[p])
{
for(int i = h[p];~i;i = ne[i])
{
int j = e[i];
if(stk.count(j))
{
continue;
}
else
{
return false;
}
}
}
}
return true;
}
int main()
{
memset(h,-1,sizeof h);
cin >> n >> m;
for(int i = 0;i < m;i++)
{
int a,b;
cin >> a >> b;
st[a] = st[b] = true;
add(a,b),add(b,a);
}
cin >> k;
for(int i = 0;i < k;i++)
{
cin >> l;
for(int j = 0;j < l;j++)
{
cin >> del;
stk.insert(del);
}
if(dfs())
{
cout << "YES" << endl;
}
else
{
cout << "NO" << endl;
}
stk.clear();
}
return 0;
}