var s:string; t,i,j,tmp,ans,x,y:longint; a:array[1..4,1..14] of longint; begin readln(t); while t>0 do begin dec(t); readln(s); s:=s+' '; fillchar(a,sizeof(a),0); for i:=1 to 5 do begin x:=ord(s[1])-64; delete(s,1,1); tmp:=pos(' ',s); val(copy(s,1,tmp-1),y,j); delete(s,1,tmp); a[x,y]:=1; if y=1 then a[x,14]:=1; end; ans:=5; for i:=1 to 4 do for j:=1 to 10 do begin tmp:=5-a[i,j]-a[i,j+1]-a[i,j+2]-a[i,j+3]-a[i,j+4]; if tmp