program track;
var
n,i,m,ans,bl,cl,p,p2:integer;
s:string;
sz:array['a'..'z']of integer;
a:array [1..10000]of record
name,start,fuck:char;
end;
temp:char;
b,c:array[1..30]of char;
begin
assign(input,'track.in');
assign(output,'track.out');
reset(input);
rewrite(output);
readln(n);
readln(s);
i:=0;
for temp:='a' to 'z' do
begin
i:=i+1;
sz[temp]:=i;
end;
m:=1;
i:=1;
ans:=0;
bl:=0;
cl:=0;
p:=0;
while m<=n do
begin
p2:=0;
if (sz[s[i]]=m)and(i<=n) then begin
ans:=ans+1;
a[ans].name:=s[i];
a[ans].start:='A';
a[ans].fuck:='D';
i:=i+1;
m:=m+1;
p2:=1;
end;
if bl>0 then begin
if sz[b[bl]]=m then begin
ans:=ans+1;
a[ans].name:=b[bl];
a[ans].start:='B';
a[ans].fuck:='D';
m:=m+1;
bl:=bl-1;
p2:=1;
end;
end;
if cl>0 then begin
if sz[c[cl]]=m then begin
ans:=ans+1;
a[ans].name:=c[bl];
a[ans].start:='C';
a[ans].fuck:='D';
m:=m+1;
cl:=cl-1;
p2:=0;
end;
end;
if p2=0 then
if (bl=0)and(i<=n) then begin
ans:=ans+1;
a[ans].name:=s[i];
a[ans].start:='A';
a[ans].fuck:='B';
bl:=bl+1;
b[bl]:=s[i];
i:=i+1;
end
else begin
if (sz[b[bl]]>sz[s[i]])and(i<=n) then begin
ans:=ans+1;
a[ans].name:=s[i];
a[ans].start:='A';
a[ans].fuck:='B';
bl:=bl+1;
b[bl]:=s[i];
i:=i+1;
end
else begin
if (cl=0)and(i<=n) then begin
ans:=ans+1;
a[ans].name:=s[i];
a[ans].start:='A';
a[ans].fuck:='C';
cl:=cl+1;
c[cl]:=s[i];
i:=i+1;
end
else begin
if (sz[c[cl]]>sz[s[i]])and(i<=n) then begin
ans:=ans+1;
a[ans].name:=s[i];
a[ans].start:='A';
a[ans].fuck:='C';
cl:=cl+1;
c[cl]:=s[i];
i:=i+1;
end
else begin
if bl>0 then begin
if cl=0 then begin
ans:=ans+1;
a[ans].name:=b[bl];
a[ans].start:='B';
a[ans].fuck:='C';
cl:=cl+1;
c[cl]:=b[bl];
bl:=bl-1;
end
else begin
if sz[c[cl]]>sz[b[bl]] then begin
ans:=ans+1;
a[ans].name:=b[bl];
a[ans].start:='B';
a[ans].fuck:='C';
cl:=cl+1;
c[cl]:=b[bl];
bl:=bl-1;
end
else begin
p:=1;
writeln('NO');
end;
end;
end;
end;
end;
end;
end;
end;
if p=0 then begin
for i:=1 to ans do
begin
writeln(a[i].name,' ',a[i].start,' ',a[i].fuck);
end;
end;
close(input);
close(output);
end.