#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <queue>
#include <vector>
#ifdef WIN32
#define TAT "%I64d"
#else
#define TAT "%lld"
#endif 
#define int64 long long
#define wc(c) freopen(c".in","r",stdin);   freopen(c".out","w",stdout);
using namespace std;
const int mode = 1e9 + 7;
int n,m,w[55][55],rx[2550],ry[2550];
int s,t,seq[110],l,r,len,f[1010][1010][2];
int head[55],next[1001000],to[1001000],val[1001000],kind[1001000],top;
vector <int> S[2550];

#define inc(x,y) x + y < mode ? x + y : x + y - mode
void link(int x,int y,int z,int h)
{
	next[++top] = head[x];   head[x] = top;   to[top] = y;   val[top] = z;   kind[top] = h;
}
void getit(int node,int sign)
{
	if (l == r)
		{
			if (sign == -1)   s = node;
			else t = node;
			return ;
		}
	if (sign > 0)
		if (!w[node][seq[l + 1]] || r > 2 * n)    return ;
		else ;
	else if (!w[seq[l + 1]][node] || r > 2 * n)    return ;
	int whe = w[node][seq[l + 1]];
	if (sign < 0)    whe = w[seq[l + 1]][node];
	if (sign == 1)   {
		for (int i = 1;i < S[whe].size();i++)
			seq[++r] = S[whe][i];
	}else {
		for (int i = S[whe].size() - 1;i >= 1;i--)
			seq[++r] = S[whe][i];
	}
	getit(seq[++l],sign);
}
void prep()
{
	for (int x1 = 1;x1 <= n;x1++)
		for (int x2 = 1;x2 <= n;x2++)
			{
				int i = w[x1][x2];
				if (S[i].size() > 1)
					{
						if (S[i][1] == ry[i])
							{
								s = rx[i];   t = 0;   l = 1;   r = 0;
								for (int j = 1;j < S[i].size();j++)   seq[++r] = S[i][j];
								getit(ry[i],1);
								if (t)    link(s,t,r,1);
							}
						for (int j = 1;j < S[i].size() - 1;j++)
							{
								if (S[i][j] != rx[i] || S[i][j + 1] != ry[i])    continue ;
								t = rx[i];   l = 1;   r = 0;
								for (int k = j;k >= 1;k--)   seq[++r] = S[i][k];
								getit(t,-1);   len = r;
								l = 1;   r = 0;
								for (int k = j + 1;k < S[i].size();k++)    seq[++r] = S[i][k];
								getit(ry[i],1);    len += r;
								if (s && t && len <= 2 * n)	 link(s,t,len - 1,2);
							}
					}else if (i)    link(rx[i],ry[i],1,4);
				i = w[x2][x1];
				if (S[i].size () <= 1)    continue ;
				if (S[i][S[i].size() - 1] == rx[i])
					{
						t = rx[i];   s = 0;   l = 1;   r = 0;
						for (int j = S[i].size() - 1;j >= 1;j--)   seq[++r] = S[i][j];
						getit(rx[i],-1);
						if (s)    link(s,ry[i],r,3);
					}
			}
}
void work()
{
	prep();
	for (int i = 1;i <= n;i++)    f[0][i][0] = 1;
	for (int len = 0;len < 2 * n;len++)
		for (int i = 1;i <= n;i++)
			for (int s = 0;s <= 1;s++)
				{
					if (!f[len][i][s])    continue ;
					if (s == 0)   {
						for (int j = head[i],y;y = to[j],j;j = next[j])
							{
								if (kind[j] == 1 || kind[j] == 4)    continue ;
								f[len + val[j]][y][kind[j] == 2] = inc(f[len + val[j]][y][kind[j] == 2],f[len][i][s]);
							}
					}else {
						for (int j = head[i],y;y = to[j],j;j = next[j])
							{
								if (kind[j] == 2 || kind[j] == 3)    continue ;
								f[len + val[j]][y][kind[j] == 1] = inc(f[len + val[j]][y][kind[j] == 2],f[len][i][s]);
							}			
					}
				}
	for (int len = 1;len <= 2 * n;len++)
		{
			int ans = 0;
			for (int i = 1;i <= n;i++)    ans = inc(ans,f[len][i][1]);
			printf("%d\n",ans);
		}
}

int main()
{
	cin >> n >> m;   int x,y,z;
	for (int i = 1;i <= m;i++)
		{
			scanf("%d %d",&x,&y);
			w[x][y] = i;   rx[i] = x,ry[i] = y;
			scanf("%d",&z);
			S[i].resize(z + 1);
			for (int j = 1;j <= z;j++)    scanf("%d",&S[i][j]);
		}
	work();
}
  
