#include <bits/stdc++.h>
using namespace std;
struct Edge {
  int a, b;
  vector<int> p;
} e[2000];
vector<int> g[110][110], h[110][110];
int dp[110][110][110];
int n, m, map[110][110];
int val[110][110][110];
void add(int &a, int b) {
  a += b;
  if (a >= 1000000007) a -= 1000000007;
}
void read() {
  scanf("%d %d", &n, &m);
  for (int i = 1; i <= m; ++i) {
    int tot;
    scanf("%d %d %d", &e[i].a, &e[i].b, &tot);
    for (int j = 1, x; j <= tot; ++j) {
      scanf("%d", &x);
      e[i].p.push_back(x);
    }
    map[e[i].a][e[i].b] = i;
  }
}
void findpath(int ide, int id1, int id2) {
  static int q1[110 * 2], q2[110 * 2];
  int rear1 = 0, rear2 = 0;
  for (int i = id1; i >= 0; --i) q1[++rear1] = e[ide].p[i];
  int front1 = 1, front2 = 1;
  while (rear1 <= 2 * n && front1 < rear1) {
    int p = q1[front1], q = q1[++front1], id = map[q][p];
    if (id == 0) return;
    for (int i = (int)e[id].p.size() - 1; i >= 0 && rear1 <= 2 * n; --i)
      q1[++rear1] = e[id].p[i];
  }
  for (int i = id2; i < (int)e[ide].p.size(); ++i) q2[++rear2] = e[ide].p[i];
  while (rear2 <= 2 * n && front2 < rear2) {
    int p = q2[front2], q = q2[++front2], id = map[p][q];
    if (id == 0) return;
    for (int i = 0; i < (int)e[id].p.size() && rear2 <= 2 * n; ++i)
      q2[++rear2] = e[id].p[i];
  }
  if (rear1 + rear2 > 2 * n) return;
  ++dp[rear1 + rear2 - 1][q1[rear1]][q2[rear2]];
}
void findpath1(int ide, int p) {
  static int queue[110 * 2];
  int rear = 0;
  for (int i = 0; i < (int)e[ide].p.size(); ++i) queue[++rear] = e[ide].p[i];
  int front = 1;
  while (rear <= n * 2 && front < rear) {
    int p = queue[front], q = queue[++front], id = map[p][q];
    if (id == 0) return;
    for (int i = 0; i < (int)e[id].p.size() && rear <= 2 * n; ++i)
      queue[++rear] = e[id].p[i];
  }
  if (rear > n * 2) return;
  g[p][queue[rear]].push_back(rear);
}
void findpath2(int ide, int p) {
  static int queue[110 * 2];
  int rear = 0;
  for (int i = (int)e[ide].p.size() - 1; i >= 0; --i)
    queue[++rear] = e[ide].p[i];
  int front = 1;
  while (rear <= n * 2 && front < rear) {
    int p = queue[front], q = queue[++front], id = map[q][p];
    if (id == 0) return;
    for (int i = (int)e[id].p.size() - 1; i >= 0 && rear <= 2 * n; ++i)
      queue[++rear] = e[id].p[i];
  }
  if (rear > 2 * n) return;
  h[queue[rear]][p].push_back(rear);
}
void work() {
  for (int i = 1; i <= m; ++i)
    for (int j = 1; j < (int)e[i].p.size(); ++j)
      if ((int)e[i].p.size() <= 2 * n && e[i].p[j] == e[i].b &&
          e[i].p[j - 1] == e[i].a)
        findpath(i, j - 1, j);
  for (int i = 1; i <= m; ++i)
    if (e[i].p.size() && e[i].p[0] == e[i].b) findpath1(i, e[i].a);
  for (int i = 1; i <= m; ++i)
    if (e[i].p.size() && e[i].p[(int)e[i].p.size() - 1] == e[i].a)
      findpath2(i, e[i].b);
  for (int i = 1; i <= n; ++i)
    for (int j = 1; j <= n; ++j) {
      sort(g[i][j].begin(), g[i][j].end());
      sort(h[i][j].begin(), h[i][j].end());
    }
  for (int i = 1; i <= 2 * n; ++i)
    for (int a = 1; a <= n; ++a)
      for (int b = 1; b <= n; ++b)
        for (int c = 1; c <= n; ++c)
          for (__typeof(g[b][c].begin()) p = g[b][c].begin();
               p != g[b][c].end(); ++p) {
            if (*p >= i) break;
            add(dp[i][a][c], dp[i - *p][a][b]);
          }
  for (int i = 1; i <= 2 * n; ++i)
    for (int a = 1; a <= n; ++a)
      for (int b = 1; b <= n; ++b)
        for (int c = 1; c <= n; ++c)
          for (__typeof(h[a][b].begin()) p = h[a][b].begin();
               p != h[a][b].end(); ++p) {
            if (*p >= i) break;
            add(dp[i][a][c], dp[i - *p][b][c]);
          }
  for (int i = 1; i <= 2 * n; ++i)
    for (int j = 1; j <= n; ++j)
      for (int k = 1; k <= n; ++k) val[i][j][k] = dp[i][j][k];
  for (int i = 1; i <= 2 * n; ++i)
    for (int numE = 1; numE <= m; ++numE)
      if (e[numE].p.size() == 0) {
        int a = e[numE].a, b = e[numE].b;
        for (int e1 = 1; e1 < i - 1; ++e1) {
          int e2 = i - e1 - 1;
          static int p1[110], p2[110];
          int n1 = 0, n2 = 0;
          for (int p = 1; p <= n; ++p) {
            if (dp[e1][p][a]) p1[++n1] = p;
            if (val[e2][b][p]) p2[++n2] = p;
          }
          for (int x = 1; x <= n1; ++x)
            for (int y = 1; y <= n2; ++y)
              dp[i][p1[x]][p2[y]] =
                  (dp[i][p1[x]][p2[y]] +
                   (long long)dp[e1][p1[x]][a] * val[e2][b][p2[y]]) %
                  1000000007;
        }
      }
  for (int i = 1; i <= 2 * n; ++i) {
    int ans = 0;
    for (int j = 1; j <= n; ++j)
      for (int k = 1; k <= n; ++k) ans = (ans + dp[i][j][k]) % 1000000007;
    printf("%d\n", ans);
  }
}
int main() {
  read();
  work();
  return 0;
}
