1 #include <bits/stdc++.h>
2 using namespace std;
3 int trie[6005][26], fail[6005], f[105][6005], ptot, q[6005];
4 bool lst[6005];
5 char s[105];
6
7 void insert()
8 {
9 int now = 0;
10 for(int i = 0; s[i]; ++i)
11 {
12 if(!trie[now][s[i] - 65])
13 trie[now][s[i] - 65] = ++ptot;
14 now = trie[now][s[i] - 65];
15 }
16 lst[now] = true;
17 }
18
19 void getfail()
20 {
21 int now, front = 0, back = 0;
22 for(int i = 0; i < 26; ++i)
23 if(trie[0][i]) q[++back] = trie[0][i];
24 while(front != back)
25 {
26 now = q[++front];
27 for(int i = 0; i < 26; ++i)
28 if(trie[now][i])
29 {
30 fail[trie[now][i]] = trie[fail[now]][i];
31 q[++back] = trie[now][i];
32 }
33 else trie[now][i] = trie[fail[now]][i];
34 if(lst[fail[now]]) lst[now] = true;
35 }
36 }
37
38 int main()
39 {
40 int n, m, ans = 1, now;
41 scanf("%d%d", &n, &m);
42 for(int i = 1; i <= n; ++i)
43 {
44 scanf("%s", s);
45 insert();
46 }
47 getfail(), f[0][0] = 1;
48 for(int i = 0; i < m; ++i)
49 for(now = 0; now <= ptot; ++now)
50 {
51 if(lst[now] || !f[i][now]) continue;
52 for(int j = 0; j < 26; ++j)
53 {
54 int k = trie[now][j];
55 (f[i + 1][k] += f[i][now]) %= 10007;
56 }
57 }
58 for(int i = 1; i <= m; ++i)
59 ans = ans * 26 % 10007;
60 for(int i = 0; i <= ptot; ++i)
61 if(!lst[i]) ans = (ans + 10007 - f[m][i]) % 10007;
62 printf("%d\n", ans);
63 return 0;
64 }