1 #include <cstdio>
2 #include <cstring>
3 #include <cstdlib>
4 #include <cmath>
5 #include <deque>
6 #include <vector>
7 #include <queue>
8 #include <iostream>
9 #include <algorithm>
10 #include <map>
11 #include <set>
12 #include <ctime>
13 using namespace std;
14 typedef long long LL;
15 typedef double DB;
16 #define For(i, s, t) for(int i = (s); i <= (t); i++)
17 #define Ford(i, s, t) for(int i = (s); i >= (t); i--)
18 #define Rep(i, t) for(int i = (0); i < (t); i++)
19 #define Repn(i, t) for(int i = ((t)-1); i >= (0); i--)
20 #define rep(i, x, t) for(int i = (x); i < (t); i++)
21 #define MIT (2147483647)
22 #define INF (1000000001)
23 #define MLL (1000000000000000001LL)
24 #define sz(x) ((int) (x).size())
25 #define clr(x, y) memset(x, y, sizeof(x))
26 #define puf push_front
27 #define pub push_back
28 #define pof pop_front
29 #define pob pop_back
30 #define ft first
31 #define sd second
32 #define mk make_pair
33 inline void SetIO(string Name) {
34 string Input = Name+".in",
35 Output = Name+".out";
36 freopen(Input.c_str(), "r", stdin),
37 freopen(Output.c_str(), "w", stdout);
38 }
39
40 const int N = 70, M = 110, Mod = 10007;
41 struct Node {
42 int Child[26], Fail;
43 bool Danger;
44 } Tr[N*M];
45 int n, m, Tot;
46 int Dp[M][N*M];
47
48 inline void Input() {
49 scanf("%d%d", &n, &m);
50 string Str;
51 For(i, 1, n) {
52 cin>>Str;
53 int Len = Str.length(), x = 0, ch;
54 Rep(j, Len) {
55 ch = Str[j]-‘A‘;
56 if(!Tr[x].Child[ch]) Tr[x].Child[ch] = ++Tot;
57 x = Tr[x].Child[ch];
58 }
59 Tr[x].Danger = 1;
60 }
61 }
62
63 queue<int> Que;
64 inline void Build() {
65 Que.push(0);
66 Tr[0].Fail = -1;
67 while(sz(Que)) {
68 int x = Que.front();
69 Que.pop();
70 Rep(c, 26) {
71 int tmp = Tr[x].Child[c];
72 if(tmp) Que.push(tmp);
73 if(!x) continue;
74 for(int tab = Tr[x].Fail; tab != -1; tab = Tr[tab].Fail)
75 if(Tr[tab].Child[c]) {
76 if(tmp) Tr[tmp].Fail = Tr[tab].Child[c];
77 else Tr[x].Child[c] = Tr[tab].Child[c];
78 break;
79 }
80 }
81 if(x) Tr[x].Danger |= Tr[Tr[x].Fail].Danger;
82 }
83 }
84
85 inline void Solve() {
86 Build();
87
88 Dp[0][0] = 1;
89 Rep(Step, m)
90 For(i, 0, Tot)
91 if(Dp[Step][i] && !Tr[i].Danger) {
92 Rep(c, 26) {
93 Dp[Step+1][Tr[i].Child[c]] += Dp[Step][i];
94 Dp[Step+1][Tr[i].Child[c]] %= Mod;
95 }
96 }
97
98 int Cnt = 0, Sum = 1, Ans;
99 For(i, 0, Tot)
100 if(!Tr[i].Danger) Cnt = (Cnt+Dp[m][i])%Mod;
101 Rep(i, m) Sum = (Sum*26)%Mod;
102 Ans = (Sum-Cnt+Mod)%Mod;
103 printf("%d\n", Ans);
104 }
105
106 int main() {
107 #ifndef ONLINE_JUDGE
108 SetIO("1030");
109 #endif
110 Input();
111 Solve();
112 return 0;
113 }