#include <bits/stdc++.h>
using namespace std;
const int mod = 1000000007;
int n, m, a[105 * 105], b[105 * 105], c[105 * 105][105], g1[105][105],
    g2[105][105], cnt[105][105][105], dp[105][105], len[105 * 105];
queue<int> q;
vector<int> a1, a2;
bool flag;
void upd(int &x, long long y) { x = (x + y) % mod; }
void solve(int t, int k) {
  int L = 0;
  q = queue<int>();
  for (int i = k + 1; i <= len[t]; ++i) {
    q.push(c[t][i]);
    if (++L > n * 2 + 1) return;
  }
  int x = 0, y = 0;
  a1.clear();
  int u = b[t];
  if (q.empty()) {
    x = u * 2 + 1;
  } else {
    if (q.front() != u) return;
    q.pop();
    while (1) {
      a1.push_back(u);
      if (q.empty()) {
        x = u * 2;
        break;
      }
      int v = q.front();
      q.pop();
      int i = g1[u][v];
      if (!i) return;
      for (int j = 1; j <= len[i]; ++j) {
        q.push(c[i][j]);
        if (++L > n * 2 + 1) return;
      }
      u = v;
    }
  }
  q = queue<int>();
  for (int i = k; i; --i) {
    q.push(c[t][i]);
    if (++L > n * 2 + 1) return;
  }
  a2.clear();
  u = a[t];
  if (q.empty()) {
    y = u * 2 + 1;
  } else {
    if (q.front() != u) return;
    q.pop();
    for (int u = a[t];;) {
      a2.push_back(u);
      if (q.empty()) {
        y = u * 2;
        break;
      }
      int v = q.front();
      q.pop();
      int i = g2[u][v];
      if (!i) return;
      for (int j = len[i]; j; --j) {
        q.push(c[i][j]);
        if (++L > n * 2 + 1) return;
      }
      u = v;
    }
  }
  ++cnt[y][x][L];
  if (x % 2 == 0 && y % 2 == 0 && !flag) {
    flag = 1;
    printf("%d\n", L);
    reverse(a2.begin(), a2.end());
    for (size_t i = 0; i < a2.size(); ++i) {
      printf("%d ", a2[i]);
    }
    for (size_t i = 0; i < a1.size(); ++i) {
      printf("%d ", a1[i]);
    }
    puts("");
  }
}
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= m; ++i) {
    scanf("%d%d%d", a + i, b + i, len + i);
    g1[a[i]][b[i]] = i;
    g2[b[i]][a[i]] = i;
    for (int j = 1; j <= len[i]; ++j) {
      int x;
      scanf("%d", &x);
      c[i][j] = x;
    }
  }
  flag = 1;
  for (int i = 1; i <= m; ++i) {
    for (int j = 0; j <= len[i]; ++j) {
      solve(i, j);
    }
  }
  if (!flag) {
    puts("0");
    puts("");
  }
  for (int i = 1; i <= n; ++i) {
    dp[0][i * 2 + 1] = 1;
  }
  for (int i = 0; i <= n * 2 + 1; ++i) {
    for (int k = 0; i + k <= n * 2 + 1; ++k) {
      for (int j = 1; j <= n * 2 + 1; ++j) {
        if (!dp[i][j]) continue;
        for (int l = 1; l <= n * 2 + 1; ++l) {
          upd(dp[i + k][l], (long long)dp[i][j] * cnt[j ^ 1][l][k]);
        }
      }
    }
  }
  for (int i = 2; i <= n * 2 + 1; ++i) {
    int ans = 0;
    for (int j = 2; j <= n * 2; j += 2) upd(ans, dp[i][j]);
    printf("%d\n", ans);
  }
  return 0;
}
