Problem: Everybody knows that we have been living in the Matrix for a long time. And in the new seventh Matrix the world is ruled by beavers.

So let's take beaver Neo. Neo has so-called "deja vu" outbursts when he gets visions of events in some places he's been at or is going to be at. Let's examine the phenomenon in more detail.

We can say that Neo's city is represented by a directed graph, consisting of n shops and m streets that connect the shops. No two streets connect the same pair of shops (besides, there can't be one street from A to B and one street from B to A). No street connects a shop with itself. As Neo passes some streets, he gets visions. No matter how many times he passes street k, every time he will get the same visions in the same order. A vision is a sequence of shops.

We know that Neo is going to get really shocked if he passes the way from some shop a to some shop b, possible coinciding with a, such that the list of visited shops in the real life and in the visions coincide.

Suggest beaver Neo such path of non-zero length. Or maybe you can even count the number of such paths modulo 1000000007 (109 + 7)?..

Input

The first line contains integers n and m — the number of shops and the number of streets, correspondingly, 1 ≤ n ≤ 50, <image>. Next m lines contain the descriptions of the streets in the following format: xi yi ki v1 v2 ... vk, where xi and yi (1 ≤ xi, yi ≤ n, xi ≠ yi) are indices of shops connected by a street, ki (0 ≤ ki ≤ n) is the number of visions on the way from xi to yi; v1, v2, ..., vk (1 ≤ vi ≤ n) describe the visions: the numbers of the shops Neo saw. Note that the order of the visions matters.

It is guaranteed that the total number of visions on all streets doesn't exceed 105.

  * to get 50 points, you need to find any (not necessarily simple) path of length at most 2·n, that meets the attributes described above (subproblem E1); 
  * to get 50 more points, you need to count for each length from 1 to 2·n the number of paths that have the attribute described above (subproblem E2). 

Output

Subproblem E1. In the first line print an integer k (1 ≤ k ≤ 2·n) — the numbers of shops on Neo's path. In the next line print k integers — the number of shops in the order Neo passes them. If the graph doesn't have such paths or the length of the shortest path includes more than 2·n shops, print on a single line 0.

Subproblem E2. Print 2·n lines. The i-th line must contain a single integer — the number of required paths of length i modulo 1000000007 (109 + 7).

Examples

Input

6 6
1 2 2 1 2
2 3 1 3
3 4 2 4 5
4 5 0
5 3 1 3
6 1 1 6


Output

4
6 1 2 3


Input

6 6
1 2 2 1 2
2 3 1 3
3 4 2 4 5
4 5 0
5 3 1 3
6 1 1 6


Output

1
2
1
1
2
1
1
2
1
1
2
1

Note

The input in both samples are the same. The first sample contains the answer to the first subproblem, the second sample contains the answer to the second subproblem.

Solution (in CPP):

Solution:
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC optimize("inline", "fast-math", "unroll-loops", \
                     "no-stack-protector")
#pragma GCC target("popcnt,tune=native")
using namespace std;
namespace io {
const int SIZE = (1 << 21) + 1;
char ibuf[SIZE], *iS, *iT, obuf[SIZE], *oS = obuf, *oT = oS + SIZE - 1, c,
                                       qu[55];
int f, qr;
inline void flush() {
  fwrite(obuf, 1, oS - obuf, stdout);
  oS = obuf;
}
inline void putc(char x) {
  *oS++ = x;
  if (oS == oT) flush();
}
template <class T>
inline void getc(T &x) {
  for (c = (iS == iT ? (iT = (iS = ibuf) + fread(ibuf, 1, SIZE, stdin),
                       (iS == iT ? EOF : *iS++))
                     : *iS++);
       !((c >= '0' && c <= '9') || (c >= 'a' && c <= 'z') ||
         (c >= 'A' && c <= 'Z'));
       c = (iS == iT ? (iT = (iS = ibuf) + fread(ibuf, 1, SIZE, stdin),
                       (iS == iT ? EOF : *iS++))
                     : *iS++))
    ;
  x = c;
}
template <class I>
inline void rd(I &x) {
  for (f = 1, c = (iS == iT ? (iT = (iS = ibuf) + fread(ibuf, 1, SIZE, stdin),
                              (iS == iT ? EOF : *iS++))
                            : *iS++);
       c < '0' || c > '9';
       c = (iS == iT ? (iT = (iS = ibuf) + fread(ibuf, 1, SIZE, stdin),
                       (iS == iT ? EOF : *iS++))
                     : *iS++))
    if (c == '-') f = -1;
  for (x = 0; c <= '9' && c >= '0';
       c = (iS == iT ? (iT = (iS = ibuf) + fread(ibuf, 1, SIZE, stdin),
                       (iS == iT ? EOF : *iS++))
                     : *iS++))
    x = x * 10 + (c & 15);
  x *= f;
}
template <class I>
inline void print(I x) {
  if (!x) putc('0');
  if (x < 0) putc('-'), x = -x;
  while (x) qu[++qr] = x % 10 + '0', x /= 10;
  while (qr) putc(qu[qr--]);
}
struct Flusher_ {
  ~Flusher_() { flush(); }
} io_flusher_;
}  // namespace io
using io ::getc;
using io ::print;
using io ::putc;
using io ::rd;
const int MAXN = 100 + 5;
const int MOD = 1e9 + 7;
int mo(int x, int y) { return (x + y) >= MOD ? (x + y - MOD) : (x + y); }
int sub(int x, int y) { return x < y ? (x - y + MOD) : (x - y); }
int ksm(int x, int y) {
  int res = 1;
  for (; y; y >>= 1, x = 1ll * x * x % MOD)
    if (y & 1) res = 1ll * res * x % MOD;
  return res;
}
void fix(int &x, const int &v) { x = (x + v) >= MOD ? (x + v - MOD) : (x + v); }
int n, m;
bool vis[MAXN][MAXN];
vector<int> e[MAXN][MAXN];
void add(int x, int y, vector<int> t) {
  vis[x][y] = 1;
  e[x][y] = t;
}
struct Node {
  vector<int> g[MAXN][MAXN];
  vector<int> solvemid() {
    vector<int> nxt, res, now;
    for (int x = 1; x <= n; x++)
      for (int y = 1; y <= n; y++)
        for (int i = 0; i + 1 < e[x][y].size(); i++)
          if (e[x][y][i] == x && e[x][y][i + 1] == y) {
            now.clear();
            nxt = e[x][y];
            bool flag = 1;
            do {
              now = nxt;
              nxt.clear();
              flag = (now.size() <= (2 * n + 1));
              for (int i = 0; i + 1 < now.size() && flag; i++) {
                if (!vis[now[i]][now[i + 1]]) {
                  flag = 0;
                  break;
                }
                nxt.insert(nxt.end(), e[now[i]][now[i + 1]].begin(),
                           e[now[i]][now[i + 1]].end());
              }
            } while (flag && now != nxt);
            if (flag) {
              if (!res.size()) res = nxt;
              g[nxt[0]][nxt.back()].push_back(nxt.size() - 1);
            }
            break;
          }
    return res;
  }
  void solvefront() {
    vector<int> nxt, res, now, Cnt;
    for (int x = 1; x <= n; x++)
      for (int y = 1; y <= n; y++)
        if (e[x][y].size() && e[x][y].back() == x) {
          now.clear();
          nxt.clear();
          nxt.push_back(x);
          bool flag = 1;
          do {
            now = nxt;
            nxt.clear();
            flag = (now.size() <= (2 * n + 1));
            nxt = e[now[0]][y];
            reverse(nxt.begin(), nxt.end());
            for (int i = 0; i + 1 < now.size() && flag; i++) {
              if (!vis[now[i + 1]][now[i]]) {
                flag = 0;
                break;
              }
              nxt.insert(nxt.end(), e[now[i + 1]][now[i]].rbegin(),
                         e[now[i + 1]][now[i]].rend());
            }
          } while (flag && now != nxt);
          if (flag) g[nxt.back()][y].push_back(nxt.size());
        }
  }
  void solveend() {
    vector<int> nxt, res, now, Cnt;
    for (int x = 1; x <= n; x++)
      for (int y = 1; y <= n; y++)
        if (e[x][y].size() && e[x][y][0] == y) {
          now.clear();
          nxt.clear();
          nxt.push_back(y);
          bool flag = 1;
          do {
            now = nxt;
            nxt.clear();
            flag = (now.size() <= (2 * n + 1));
            nxt = e[x][now[0]];
            for (int i = 0; i + 1 < now.size() && flag; i++) {
              if (!vis[now[i]][now[i + 1]]) {
                flag = 0;
                break;
              }
              nxt.insert(nxt.end(), e[now[i]][now[i + 1]].begin(),
                         e[now[i]][now[i + 1]].end());
            }
          } while (flag && now != nxt);
          if (flag) g[x][nxt.back()].push_back(nxt.size());
        }
  }
  int dp[MAXN][MAXN][MAXN];
  void solveA() {
    for (int i = 1; i <= n; i++) dp[i][i][0] = 1;
    for (int i = 0; i <= n * 2; i++)
      for (int s = 1; s <= n; s++)
        for (int l = 1; l <= n; l++)
          for (int r = 1; r <= n; r++)
            for (auto &len : g[l][r])
              if (i + len <= 2 * n + 1) fix(dp[s][r][i + len], dp[s][l][i]);
  }
} A, B, C;
int dp[MAXN][MAXN][MAXN], dp0[MAXN][MAXN][MAXN], ans[MAXN][MAXN];
int main() {
  rd(n);
  rd(m);
  for (int i = 1, a, b, K; i <= m; i++) {
    rd(a);
    rd(b);
    rd(K);
    vector<int> v;
    v.resize(K);
    for (int i = 0; i < K; i++) rd(v[i]);
    add(a, b, v);
  }
  A.solvefront();
  vector<int> res = B.solvemid();
  C.solveend();
  A.solveA();
  for (int i = 0; i <= n * 2; i++)
    for (int s = 1; s <= n; s++)
      for (int l = 1; l <= n; l++)
        for (int r = 1; r <= n; r++)
          for (auto &len : B.g[l][r])
            if (i + len <= 2 * n) fix(dp[s][r][i + len], A.dp[s][l][i]);
  for (int i = 0; i <= n * 2; i++)
    for (int s = 1; s <= n; s++)
      for (int l = 1; l <= n; l++)
        for (int r = 1; r <= n; r++)
          for (auto &len : C.g[l][r])
            if (i + len <= 2 * n) fix(dp[s][r][i + len], dp[s][l][i]);
  for (int l = 1; l <= n; l++)
    for (int mid = 1; mid <= n; mid++)
      if (vis[l][mid] && e[l][mid].empty())
        for (int r = 1; r <= n; r++)
          for (int i = 0; i + 1 <= 2 * n; i++)
            fix(dp0[l][r][i + 1], dp[mid][r][i]);
  for (int l = 1; l <= n; l++)
    for (int r = 1; r <= n; r++)
      for (int len = 1; len <= 2 * n; len++) fix(ans[r][len], dp[l][r][len]);
  for (int i = 1; i <= 2 * n; i++)
    for (int l = 1; l <= n; l++)
      for (int r = 1; r <= n; r++)
        for (int len = 1; len + i <= 2 * n; len++)
          fix(ans[r][len + i], 1ll * ans[l][i] * dp0[l][r][len] % MOD);
  for (int i = 1; i <= 2 * n; i++) {
    int aa = 0;
    for (int s = 1; s <= n; s++) fix(aa, ans[s][i]);
    print(aa);
    putc('\n');
  }
  return 0;
}