#include<bits/stdc++.h>
using namespace std;
int n,m,a,b,x,y,s[1000010],top;
vector <int> q[1000010];
bool p[10000010];
vector <vector <int> > ans;
bool dfs(int v,int fa)
{
if(p[v])
{
int x;
vector <int> e;
e.push_back(v);
x = s[top];
while(s[top] != v)
{
e.push_back(s[top --]);
p[v] = 0;
x = s[top];
}
e.push_back(v);
ans.push_back(e);
return 1;
}
s[++ top] = v;
p[v] = 1;
bool e = 0;
bool l = 1;
for(int i = 0;i < q[v].size();)
{
int u = q[v][i];
l = 0;
q[v].erase(q[v].begin() + i);
if(u == fa) continue;
if(dfs(u,v)) e = 1;
}
p[v] = 0;
if(l) return 1;
return e;
}
int main()
{
ios::sync_with_stdio(0);
cin >> n >> m;
for(int i = 1;i <= m;i ++)
{
cin >> a >> b >> x >> y;
if(x != y)
{
q[a].push_back(b);
q[b].push_back(a);
}
}
for(int i = 1;i <= n;i ++)
{
if(!dfs(i,0))
{
cout << "NIE\n";
return 0;
}
}
int r = ans.size();
cout << r << endl;
for(int i = 0;i < r;i ++)
{
int l = ans[i].size();
cout << l - 1 << ' ';
for(int j = 0;j < l;j ++)
cout << ans[i][j] << ' ';
cout << endl;
}
return 0;
}