#include using namespace std; namespace IO{ templateinline bool read(T &x){ x=0; char ch=getchar(); bool flag=0,ret=0; while(ch<'0'||ch>'9') flag=flag||(ch=='-'),ch=getchar(); while(ch>='0'&&ch<='9') x=x*10+ch-'0',ch=getchar(),ret=1; x=flag?-x:x; return ret; } templateinline bool read(T& a,Args& ...args){ return read(a)&&read(args...); } templatevoid prt(T x){ if(x>9) prt(x/10); putchar(x%10+'0'); } templateinline void put(T x){ if(x<0) putchar('-'),x=-x; prt(x); } templateinline void put(char ch,T x){ if(x<0) putchar('-'),x=-x; prt(x); putchar(ch); } templateinline void put(T a,Args ...args){ put(a); put(args...); } templateinline void put(const char ch,T a,Args ...args){ put(ch,a); put(ch,args...); } inline void putstr(string s){ for(int i=0,sz=s.length();i edge[N<<1],p[N<<2]; inline void update(int x,int l,int r,int ul,int ur,int w){ if(ul>ur) return; if(ul<=l&&ur>=r) return p[x].emplace_back(w),void(); int mid=l+r>>1; if(ul<=mid) update(lc(x),l,mid,ul,ur,w); if(ur>mid) update(rc(x),mid+1,r,ul,ur,w); } inline int getf(int x){ while(x!=fa[x]) x=fa[x]; return x; } inline void merge(int x,int y){ // x=getf(x),y=getf(y); if(dep[x]>dep[y]) swap(x,y); fa[x]=y; op[++tp]=(operation){x,y,siz[x],dep[x]==dep[y]}; siz[y]+=siz[x]; if(dep[x]==dep[y]) dep[y]++; } inline void pop(){ dep[op[tp].y]-=op[tp].val; siz[op[tp].y]-=op[tp].siz; fa[op[tp].x]=op[tp].x; tp--; } void solve(int x,int l,int r,int flag){ int lst=tp; for(auto now:p[x]){ int a=getf(e[now].u),b=getf(e[now].v); if(a==b) continue; merge(a,b); if(siz[a]==n||siz[b]==n) flag=1; } if(l==r) ans[l]=flag; else{ int mid=l+r>>1; solve(lc(x),l,mid,flag),solve(rc(x),mid+1,r,flag); } while(tp>lst) pop(); } int main(){ read(n,m); for(int i=1;i<=m;i++) read(e[i].u,e[i].v),edge[i].emplace_back(0); read(k); for(int i=1,x,y;i<=k;i++){ read(x); while(x--) read(y),edge[y].emplace_back(i); } for(int i=1;i<=m;i++) edge[i].emplace_back(k+1); for(int i=1;i<=m;i++) for(int j=1;j