#include <cstdio>
#include <cstring>
#include <iostream>
using namespace std;
const int N = 100010, M = 2000010;
int sum;
int n, m;
int d[N];
bool st[M];
int ans[M], cnt;
int h[N], e[M], ne[M], idx;
void add(int a, int b)
{
e[idx] = b;
ne[idx] = h[a];
h[a] = idx;
idx ++ ;
}
void dfs(int u, int root)
{
ans[++ cnt] = u;
d[u] -= 2;
for (int i = h[u]; i != -1; i = ne[i])
{
h[u] = i;
int j = e[i];
if (st[i]) continue;
st[i] = st[i ^ 1] = true;
if (j == root && u != root)
{
sum ++ ;
ans[++ cnt] = j;
return ;
}
dfs(j, root);
return ;
}
}
int main()
{
cin >> n >> m;
memset(h, -1, sizeof h);
for (int i = 1; i <= m; i ++ )
{
int a, b, s, t;
scanf("%d %d %d %d", &a, &b, &s, &t);
if (s ^ t)
{
add(a, b);
add(b, a);
d[a] ++ , d[b] ++ ;
}
}
for (int i = 1; i <= n; i ++ )
if (d[i] & 1)
{
puts("NIE");
return 0;
}
for (int i = 1; i <= n; i ++ )
{
if (!d[i]) continue;
while (d[i]) dfs(i, i);
}
printf("%d\n", sum);
for (int i = 1; i <= cnt; i ++ )
{
int root = ans[i];
int j = i + 1;
while (ans[j] != root && j <= cnt) j ++ ;
printf("%d ", j - i);
for (int k = i; k <= j; k ++ ) printf("%d ", ans[k]);
i = j;
puts("");
}
return 0;
}