My Solution Here:
program lonesome;
const
dx:array[1..8]of integer
=(1,2,2,1,-1,-2,-2,-1);
dy:array[1..8]of integer
=(2,1,-1,-2,-2,-1,1,2);
var
strr:string[2];
num,n,i,x,y:integer;
procedure solve(x,y:integer);
var
i,tempx,tempy:integer;
begin
for i:=1 to 8 do
begin
tempx:=x+dx[i];
tempy:=y+dy[i];
if (tempx>=1) and (tempx<=8) then
if (tempy>=1) and (tempy<=8) then
inc(num);
end;
end;
begin
readln(n);
for i:=1 to n do
begin
readln(strr);
x:=ord(strr[1])-ord('a')+1;
y:=ord(strr[2])-ord('0');
num:=0;
solve(x,y);
writeln(num);
end;
end.