#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 2e6+10, M = 1e5+10;
struct node{
int to,ne;
}edge[N];
int n, m;
int d[M],st[N],f[N];
int head[N],cnt;
int ans,tot;
void add(int a,int b){
edge[cnt].to = b;
edge[cnt].ne = head[a];
head[a] = cnt++;
}
void dfs(int u,int root)
{
f[++tot]=u;
d[u]-=2;
for(int i=head[u];i!=-1;i=edge[i].ne)
{
int j = edge[i].to;
if(st[i]) continue;
st[i]=st[i^1]=1;
if(u!=root&&j==root)
{
ans++;
f[++tot]=j;
return;
}
dfs(j,root);
return;
}
}
int main()
{
memset(head,-1,sizeof head);
scanf("%d%d",&n,&m);
for(int i = 1; i <= m; i++ ){
int x,y,z,w;
scanf("%d%d%d%d",&x,&y,&z,&w);
if(z^w){
add(x,y);
add(y,x);
d[x]++;
d[y]++;
}
}
for(int i = 1; i <= n; i++ ){
if(d[i]%2){
printf("NIE\n");
return 0;
}
}
for(int i = 1; i <= n; i++ ){
if(!d[i]) continue;
while(d[i]) dfs(i,i);
}
printf("%d\n",ans);
int i = 1;
while(i<=tot){
int root = f[i], k = 1;
i++;
while(f[i]!=root&&i<=tot) i++,k++;
printf("%d ",k);
for(int j = i-k; j <= i; j++ ) printf("%d ",f[j]);
printf("\n");
i++;
}
return 0;
}