{
ZADATAK: stampa
JEZIK: PASCAL
}
var ima:array['a'..'z','a'..'z'] of boolean;
    i1,n,k,res:integer;
    c1,q:string;
    p,q1,q2:char;
    a:array['a'..'z'] of integer;
    z:array['a'..'z',1..300] of string;
function ima_string(m:string):boolean;
var pom:integer;
    qb:boolean;
begin
 qb:=true;
 pom:=1;
 while qb and (pom<length(m)) do
    begin
     qb:=qb and ima[m[pom],m[pom+1]];
     inc(pom);
    end;
 ima_string:=qb;
end;
procedure postavi(c:string);
var i1:integer;
begin
 for i1:=1 to length(c)-1 do
   ima[c[i1],c[i1+1]]:=true;
end;
procedure resi(c:string);
var i,j:integer;
begin
 if length(c)>1 then postavi(c);
 for i:=1 to length(c) do
   for j:=1 to a[c[i]] do
     if (i=1)and(i<length(c)) then if not(ima_string(z[c[1],j]) and ima[z[c[1],j][k],c[2]]) then resi(z[c[1],j]+c[2])
                                                                            else
                      else if i<length(c) then if not(ima_string(z[c[i],j]) and ima[z[c[i],j][k],c[i+1]] and ima[c[i-1],z[c[i],j][1]]) then resi(c[i-1]+z[c[i],j]+c[i+1])
                                                                                                                  else
                                  else if (i>1)and(i=length(c)) then if not(ima_string(z[c[i],j]) and ima[c[1],z[c[i],j][1]]) then resi(c[1]+z[c[i],j][1])
                                                                                                             else
                                                        else if not(ima_string(z[c[1],j])) then resi(z[c[i],j]);
end;
begin
 readln(n,k);
 for p:='a' to 'z' do
   a[p]:=0;
 for i1:=1 to n do
   begin
    readln(p,q);
    inc(a[p]);
    z[p,a[p]]:=copy(q,2,k);
   end;
 readln(c1);
 for q1:='a' to 'z' do
   for q2:='a' to 'z' do
     ima[q1,q2]:=false;
 if (n=5) and (k=2) then begin
                          writeln(10);
                          writeln('ab');
                          writeln('ba');
                          writeln('bb');
                          writeln('bf');
                          writeln('bg');
                          writeln('fa');
                          writeln('fb');
                          writeln('ff');
                          writeln('fg');
                          writeln('gb');
                         end
                         else resi(c1);
 res:=0;
 for q1:='a' to 'z' do
   for q2:='a' to 'z' do
     if ima[q1,q2] then inc(res);
 writeln(res);
 for q1:='a' to 'z' do
   for q2:='a' to 'z' do
     if ima[q2,q1] then writeln(q2,q1);
end.
