#include <bits/stdc++.h>
using namespace std;
int i, j, k, n, m, x, y, z, nn;
int id[60][60], f[60 * 2][60][60], q[60 * 2][60][60], w[60 * 2][60][60];
vector<int> a[3000], g, h;
bool dfs(int x, int y, int ty) {
  if (!ty && x == g.size() || ty && x == h.size()) return 1;
  int i;
  int A = !ty ? g[x] : h[x], B = !ty ? id[y][A] : id[A][y];
  if (!B) return 0;
  if (!ty) {
    for (i = 0; i < a[B].size(); i++) {
      int C = a[B][i];
      g.push_back(C);
      if (g.size() > nn) return 0;
    }
  } else {
    for (i = a[B].size() - 1; i >= 0; i--) {
      int C = a[B][i];
      h.push_back(C);
      if (h.size() > nn) return 0;
    }
  }
  return dfs(x + 1, A, ty);
}
inline void work1(int i, int j) {
  int A = id[i][j], wei, len = a[A].size();
  if (!A || len < 2) return;
  for (k = 0; k + 1 < a[A].size(); k++) {
    int B = a[A][k], C = a[A][k + 1], D = id[B][C];
    if (B == i && C == j) break;
  }
  if (k + 1 == len) return;
  wei = k;
  g.clear();
  for (k = wei + 1; k < len; k++) {
    int B = a[A][k];
    g.push_back(B);
    if (g.size() > nn) return;
  }
  h.clear();
  for (k = wei; k >= 0; k--) {
    int B = a[A][k];
    h.push_back(B);
    if (h.size() > nn) return;
  }
  if (dfs(1, j, 0) && dfs(1, i, 1)) {
    int B = g.size() + h.size();
    if (B <= nn) f[B - 1][i][j]++;
  }
}
inline void work2(int i, int j) {
  int A = id[i][j], len = a[A].size();
  if (!len) return;
  if (a[A][len - 1] != i) return;
  h.clear();
  for (k = len - 1; k >= 0; k--) {
    int B = a[A][k];
    h.push_back(B);
    if (h.size() > nn) return;
  }
  if (dfs(1, i, 1)) {
    int B = h.size();
    q[B][h[B - 1]][j]++;
  }
}
inline void work3(int i, int j) {
  int A = id[i][j], len = a[A].size();
  if (!len) return;
  if (a[A][0] != j) return;
  g.clear();
  for (k = 0; k < len; k++) {
    int B = a[A][k];
    g.push_back(B);
    if (g.size() > nn) return;
  }
  if (dfs(1, j, 0)) {
    int B = g.size();
    w[B][i][g[B - 1]]++;
  }
}
inline void S(int &x, int y) {
  x += y;
  if (x >= 1000000007) x -= 1000000007;
}
inline void work() {
  int u, r, v, x, y, t;
  for (i = 1; i <= nn; i++)
    for (u = 1; u <= n; u++)
      for (r = 1; r <= n; r++)
        if (x = f[i][u][r]) {
          for (j = 1; j <= nn - i; j++) {
            for (v = 1; v <= n; v++)
              if (y = q[j][v][u]) S(f[i + j][v][r], 1ll * x * y % 1000000007);
            if (i + j + 1 <= nn)
              for (v = 1; v <= n; v++) {
                int A = id[u][v];
                if (A && !a[A].size())
                  for (t = 1; t <= n; t++)
                    if (y = f[j][t][v])
                      S(f[i + j + 1][t][r], 1ll * x * y % 1000000007);
              }
          }
        }
  for (i = 1; i <= nn; i++)
    for (u = 1; u <= n; u++)
      for (r = 1; r <= n; r++)
        if (x = f[i][u][r]) {
          for (j = 1; j <= nn - i; j++) {
            for (v = 1; v <= n; v++)
              if (y = w[j][r][v]) S(f[i + j][u][v], 1ll * x * y % 1000000007);
          }
        }
}
int main() {
  scanf("%d%d", &n, &m);
  nn = n * 2;
  for (i = 1; i <= m; i++) {
    scanf("%d%d%d", &x, &y, &k);
    id[x][y] = i;
    for (j = 1; j <= k; j++) scanf("%d", &z), a[i].push_back(z);
  }
  for (i = 1; i <= n; i++)
    for (j = 1; j <= n; j++) {
      work1(i, j);
      work2(i, j);
      work3(i, j);
    }
  work();
  for (i = 1; i <= nn; i++) {
    int an = 0;
    for (j = 1; j <= n; j++)
      for (k = 1; k <= n; k++) S(an, f[i][j][k]);
    printf("%d\n", an);
  }
  return 0;
}
