#include <bits/stdc++.h>
using namespace std;
const int Max_N = 50;
const long long Mod = (1e9) + 7;
int n, m, Head, Tail, len, cnt, cntt, cnttt, mp[Max_N + 5][Max_N + 5],
    q[Max_N * Max_N + 5], g[Max_N + 5][Max_N * 2 + 5],
    h[Max_N + 5][Max_N + 5][Max_N * 2 + 5],
    dis[Max_N + 5][Max_N + 5][Max_N * 2 + 5],
    f[Max_N + 5][Max_N + 5][Max_N * 2 + 5], Ans[Max_N * 2 + 5];
vector<int> a[Max_N + 5][Max_N + 5], ans[Max_N * Max_N + 5],
    lst[Max_N * Max_N + 5], nxt[Max_N * Max_N + 5];
vector<pair<int, int> > e[Max_N + 5];
inline bool Go_Head(int x, int opt) {
  if (len > 2 * n + 1) return false;
  if (x == Head) {
    if (opt) {
      ++cntt;
      for (int i = Head; i <= Tail; i++) lst[cntt].push_back(q[i]);
      lst[cntt].push_back(opt);
    }
    return true;
  }
  if (mp[q[x - 1]][q[x]]) {
    for (int i = a[q[x - 1]][q[x]].size() - 1; i >= 0; i--)
      q[--Head] = a[q[x - 1]][q[x]][i];
    len += a[q[x - 1]][q[x]].size();
    return Go_Head(x - 1, opt);
  } else
    return false;
}
inline bool Go_Tail(int x, int opt) {
  if (len > 2 * n + 1) return false;
  if (x == Tail) {
    if (!opt) {
      ++cnt;
      for (int i = Head; i <= Tail; i++) ans[cnt].push_back(q[i]);
    } else {
      ++cnttt;
      nxt[cnttt].push_back(opt);
      for (int i = Head; i <= Tail; i++) nxt[cnttt].push_back(q[i]);
    }
    return true;
  }
  if (mp[q[x]][q[x + 1]]) {
    for (int i = 0; i < a[q[x]][q[x + 1]].size(); i++)
      q[++Tail] = a[q[x]][q[x + 1]][i];
    len += a[q[x]][q[x + 1]].size();
    return Go_Tail(x + 1, opt);
  } else
    return false;
}
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= m; i++) {
    int u, v, K;
    scanf("%d%d%d", &u, &v, &K);
    mp[u][v] = 1;
    for (int j = 1; j <= K; j++) {
      int x;
      scanf("%d", &x);
      a[u][v].push_back(x);
    }
  }
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= n; j++)
      if (a[i][j].size()) {
        Head = 4 * n + 1;
        Tail = 4 * n;
        for (int k = 0; k < a[i][j].size(); k++) q[++Tail] = a[i][j][k];
        int x = 0;
        len = a[i][j].size();
        for (int k = Head; k < Tail; k++)
          if (q[k] == i && q[k + 1] == j) {
            x = k;
            break;
          }
        if (x) {
          if (!Go_Head(x, 0)) continue;
          if (!Go_Tail(x + 1, 0)) continue;
        } else if (q[Tail] == i)
          Go_Head(Tail, j);
        else if (q[Head] == j)
          Go_Tail(Head, i);
      }
  printf("%d\n", ans[1].size());
  for (int i = 0; i < ans[1].size(); i++) printf("%d ", ans[1][i]);
  puts("");
  for (int i = 1; i <= cntt; i++)
    e[lst[i][0]].push_back(
        make_pair(lst[i][lst[i].size() - 1], lst[i].size() - 1)),
        ++dis[lst[i][0]][lst[i][lst[i].size() - 1]][lst[i].size() - 1];
  for (int l = 1; l <= 2 * n; l++)
    for (int i = 1; i <= n; i++)
      for (int j = 1; j <= n; j++)
        for (int k = 0; k < e[j].size(); k++)
          if (l + e[j][k].second <= 2 * n)
            dis[i][e[j][k].first][l + e[j][k].second] =
                (dis[i][e[j][k].first][l + e[j][k].second] + dis[i][j][l]) %
                Mod;
  for (int i = 1; i <= n; i++) e[i].clear();
  for (int i = 1; i <= cnt; i++)
    e[ans[i][0]].push_back(
        make_pair(ans[i][ans[i].size() - 1], ans[i].size() - 1)),
        ++f[ans[i][0]][ans[i][ans[i].size() - 1]][ans[i].size() - 1];
  for (int l = 1; l <= 2 * n; l++)
    for (int i = 1; i <= n; i++)
      for (int j = 1; j <= n; j++)
        for (int k = 0; k < e[j].size(); k++)
          if (l + e[j][k].second <= 2 * n)
            f[i][e[j][k].first][l + e[j][k].second] =
                (f[i][e[j][k].first][l + e[j][k].second] + dis[i][j][l]) % Mod;
  for (int i = 1; i <= n; i++) e[i].clear();
  for (int i = 1; i <= cnttt; i++)
    e[nxt[i][0]].push_back(
        make_pair(nxt[i][nxt[i].size() - 1], nxt[i].size() - 1));
  for (int l = 1; l <= 2 * n; l++)
    for (int i = 1; i <= n; i++)
      for (int j = 1; j <= n; j++)
        for (int k = 0; k < e[j].size(); k++)
          if (l + e[j][k].second <= 2 * n)
            f[i][e[j][k].first][l + e[j][k].second] =
                (f[i][e[j][k].first][l + e[j][k].second] + f[i][j][l]) % Mod;
  for (int l = 1; l <= 2 * n; l++)
    for (int i = 1; i <= n; i++)
      for (int j = 1; j <= n; j++) g[j][l] = (g[j][l] + f[i][j][l]) % Mod;
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= n; j++)
      if (mp[i][j] && a[i][j].size() == 0)
        for (int k = 1; k <= n; k++)
          for (int l = 1; l < 2 * n; l++)
            h[i][k][l + 1] = (h[i][k][l + 1] + f[j][k][l]) % Mod;
  for (int l = 1; l <= 2 * n; l++)
    for (int i = 1; i <= n; i++)
      for (int k = 1; k <= n; k++)
        for (int L = 1; L + l <= 2 * n; L++)
          g[k][l + L] = (g[k][l + L] + 1ll * g[i][l] * h[i][k][L] % Mod) % Mod;
  for (int l = 1; l <= 2 * n; l++) {
    for (int i = 1; i <= n; i++) Ans[l] += g[i][l], Ans[l] %= Mod;
  }
  for (int l = 1; l <= 2 * n; l++) printf("%d\n", Ans[l]);
  return 0;
}
