1 var i,j,k,n,m,len,head,tail,p,tot,ans1,ans2,x:Longint; 2 ch:array[0..20000] of array[0..30] of Longint; 3 fail:array[0..20000] of Longint; 4 fg:array[0..20000] of Boolean; 5 q:array[0..20000] of Longint; 6 f:array[0..200] of array[0..20000] of Longint; 7 str:string; 8 9 begin 10 fillchar(ch,sizeof(ch),0); 11 fillchar(q,sizeof(q),0); 12 fillchar(f,sizeof(f),0); 13 tot:=0; 14 head:=0; 15 tail:=1; 16 fail[0]:=-1; 17 q[tail]:=0; 18 ans1:=1; 19 for i:=0 to 15000 do fg[i]:=false; 20 readln(n,m); 21 for i:=1 to n do 22 begin 23 readln(str); 24 len:=length(str); 25 p:=0; 26 for j:=1 to len do 27 begin 28 if ch[p][ord(str[j])-ord('A')]=0 then 29 begin 30 inc(tot); 31 ch[p][ord(str[j])-ord('A')]:=tot; 32 end; 33 p:=ch[p][ord(str[j])-ord('A')]; 34 end; 35 fg[p]:=true; 36 end; 37 38 while head<>tail do 39 begin 40 inc(head); 41 x:=q[head]; 42 for i:=0 to 25 do 43 begin 44 if ch[x][i]<>0 then 45 begin 46 inc(tail); 47 q[tail]:=ch[x][i]; 48 if x<>0 then 49 fail[ch[x][i]]:=ch[fail[x]][i] 50 else fail[ch[x][i]]:=0; 51 end 52 else begin 53 if x<>0 then 54 ch[x][i]:=ch[fail[x]][i] 55 else ch[x][i]:=0; 56 end; 57 end; 58 fg[x]:=fg[x] or fg[fail[x]]; 59 end; 60 f[0][0]:=1; 61 for i:=1 to m do 62 for j:=0 to tot do 63 if not fg[j] then 64 for k:=0 to 25 do 65 f[i][ch[j][k]]:=(f[i-1][j]+f[i][ch[j][k]]) mod 10007; 66 for i:=0 to tot do 67 if not fg[i] then 68 inc(ans2,f[m][i]); 69 for i:=1 to m do ans1:=(ans1*26) mod 10007; 70 writeln((((ans1-ans2) mod 10007)+10007) mod 10007); 71 end.