{
ZADATAK: stampa
JEZIK: PASCAL
}

var m:array['a'..'z','a'..'z'] of boolean;
        a:array[1..10000] of char;
        s:array[1..10000] of string[100];
        poc, kraj:array['a'..'z'] of integer;
        ch,ch1,ch2:char;
        i,n,k,x:integer;
procedure sort(l,r:integer);
var i,j:integer;
ch:char;st:string;
begin
        ch:=a[(l+r)div 2];
        i:=l; j:=r;
        repeat
        while a[i]<ch do inc(i);
        while a[j]>ch do dec(j);
        if i<=j then
        begin
                ch:=a[i]; a[i]:=a[j]; a[j]:=ch;
                st:=s[i]; s[i]:=s[j]; s[j]:=st;
                inc(i); dec(j);
        end;
        until i>j;
        if i<r then sort(i,r);
        if j>l then sort(l,j);
end;

{procedure trazi(p:string);
var i,j:integer;
begin
        for i:=1 to length(p)-1 do
        if m[p[i]][p[i+1]]<3 then
                inc(m[p[i]][p[i+1]]);
        if m[p[1]][p[2]]<3 then for i:=poc[p[1]] to kraj[p[1]] do trazi(s[i]+p[2]);
        j:=length(p);
        if m[p[j-1]][p[j]]<3 then for i:=poc[p[j]] to kraj[p[j]] do trazi(p[j-1]+s[i]);
        for i:=2 to length(p)-1 do
        if not((m[p[i-1]][p[i]]=3) and (m[p[i]][p[i+1]]=3)) then for j:=poc[p[i]] to kraj[p[i]] do trazi(p[i-1]+s[j]+p[i+1]);
end;
}

procedure trazi(p:string);
var q:array[1..1000] of string[105];
t,j,i,k:integer;
begin
        q[1]:=p;
        k:=2;i:=1;
        while i<k do
        begin
                if not m[q[i][1]][q[i][2]] then
                for j:=poc[q[i][1]] to kraj[q[i][1]] do
                begin
                        q[k]:=s[j]+q[i][2];
                        inc(k);
                end;
                t:=length(q[i]);
                if not m[q[i][t-1]][q[i][t]] then
                for j:=poc[q[i][t]] to kraj[q[i][t]] do
                begin
                        q[k]:=q[i][t-1]+s[j];
                        inc(k);
                end;
                for j:=2 to length(q[i])-1 do
                if not (m[q[i][j-1]][q[i][j]] and m[q[i][j]][q[i][j+1]]) then
                        for t:=poc[q[i][j]] to kraj[q[i][j]] do
                        begin
                                q[k]:=q[i][j-1]+s[t]+q[i][j+1];
                                inc(k);
                        end;
                for j:=1 to length(q[i])-1 do
                if not m[q[i][j]][q[i][j+1]] then begin
                m[q[i][j]][q[i][j+1]]:=true;
                inc(x);
                end;
                inc(i);
        end;
end;


begin
        x:=0;
        readln(n,k);
        for i:=1 to n do
        readln(a[i],ch1,s[i]);
        readln(ch);
        for ch1:='a' to 'z' do
        begin
        for ch2:='a' to 'z' do
        m[ch1][ch2]:=false;
        poc[ch1]:=-1;
        kraj[ch1]:=-2;
        end;
        sort(1,n);
        for i:=1 to n do
        begin
                kraj[a[i]]:=i;
                if poc[a[i]]=-1 then poc[a[i]]:=i;
        end;
        if k>1 then
        begin
        for i:=poc[ch] to kraj[ch] do
        trazi(s[i]);
{        for ch1:='a' to 'z' do
        for ch2:='a' to 'z' do
        if m[ch1][ch2]>1 then inc(x);}
        writeln(x);
        for ch1:='a' to 'z' do
        for ch2:='a' to 'z' do
        if m[ch1][ch2] then writeln(ch1,ch2);
        end
        else writeln(0);
end.


