Very Easy Solution Using C++,brute force...!
#include<bits/stdc++.h>
using namespace std;
//input section
#define si1(x) scanf("%d",&x) //one integer
#define si2(x,y) scanf("%d%d",&x,&y) //two integers
#define si3(x,y,z) scanf("%d%d%d",&x,&y,&z) //three integers
#define sl(x) scanf("%lld",&x) //long long int
#define sul(x) scanf("%llu",&x) //unsigned long long
#define ss(x) scanf("%s",s) //string
#define sd(x) scanf("%lf",&x) //double
//output section
#define pf printf
#define pfi(x) printf("%d\n",x)
#define pfl(x) printf("%lld\n",x)
#define pfd(x) printf("%lf\n",x)
#define nl printf("\n")
//data type
#define ll long long int
#define ld long double
#define ull unsigned long long
//general
#define pb push_back
#define mp make_pair
#define f first
#define s second
#define all(x) x.begin( ),x.end( )
#define sv(x) memset(x, 0, sizeof(x))
#define PI 3.1415926535897932384626
#define mod 1000000007
//loop
#define lp(a,b) for(int i=a;i<b;i++) //assending order
#define lpr(a,b) for(int i=b;i>=a;i--) //decending order
#define pl(a) pair<ll, ll>a
#define ppi(a) pair<int,int>a
#define vec(v) vector<int>v
#define vi(v,itr) vector<int>::iterator itr=v.begin( );
void solve( )
{
int cnt=0;
char s,h;
cin>>s>>h;
int p,q;
p=(int)s-96;
q=(int)h-48;
if((p+1)>=1 && (p+1)<=8 && (q-2)>=1 && (q-2)<=8) ++cnt;
if((p-1)>=1 && (p-1)<=8 && (q+2)>=1 && (q+2)<=8) ++cnt;
if((p-1)>=1 && (p-1)<=8 && (q-2)>=1 && (q-2)<=8) ++cnt;
if((p+1)>=1 && (p+1)<=8 && (q+2)>=1 && (q+2)<=8) ++cnt;
if((p+2)>=1 && (p+2)<=8 && (q-1)>=1 && (q-1)<=8) ++cnt;
if((p-2)>=1 && (p-2)<=8 && (q+1)>=1 && (q+1)<=8) ++cnt;
if((p-2)>=1 && (p-2)<=8 && (q-1)>=1 && (q-1)<=8) ++cnt;
if((p+2)>=1 && (p+2)<=8 && (q+1)>=1 && (q+1)<=8) ++cnt;
cout<<cnt<<endl;
}
int main( )
{
//code by noob coder BD (Shahariar,CSE,RUET-19)
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
//freopen("input.txt","r",stdin);
//freopen("output.txt","w",stdout);
int t=1;
cin>>t;
while(t--)
{
solve( );
}
return 0;
}