program NumbersCheck;

uses 
	testlib, sysutils;

const
	letter : set of char = ['A','B','C','E','H','K','M','O','P','T','X','Y'];
	digit  : set of char = ['0','1','2','3','4','5','6','7','8','9'];

type
	int = longint;

var
	i,j		: int;
	no,na	: int;
	s		: string;
	a		: array [1..36] of string;

function beanum(var s: string): boolean;
var
	i: int;
begin
	beanum := false;
	if (length(s) <> 6) then exit;
	
	for i := 1 to 6 do
		if i in [1,5,6] then begin
			if not (s[i] in letter) then exit
		end else begin
			if not (s[i] in digit) then exit;
		end;
	
	beanum := true;
end;

function sort(var s: string): string;
var
	i,j : int;
	ch : char;
	t:string;
begin
	t := s;
	for i := 1 to length(t) do
		for j := 1 to length(t) - 1 do
			if (t[j] < t[j + 1]) then begin
				ch := t[j];
				t[j] := t[j + 1];
				t[j + 1] := ch;	
			end;
	sort := t;          
end;

begin
	no := ouf.readlongint;
	na := ans.readlongint;
	if (no <> na) then 
		quit(_wa, format('expected: %d, found: %d', [na, no]));
	
	s := inf.readstring;
		
	ouf.nextline;

	for i := 1 to no do	begin
		a[i] := trim(ouf.readstring);
		
		if (not beanum(a[i])) then 
			quit(_pe, format('line %d is not a number', [i]));
		if (sort(a[i]) <> sort(s)) 
			then quit(_wa, format('line %d is not a permutation', [i]));
		
		for j := 1 to i - 1 do 
			if (a[i] = a[j]) then 
				quit(_wa,format('line %d is same as line %d', [i, j]));
	end;

	quit(_ok, format('%d numbers', [no]));
end.