Shortest Solution
#include<iostream>
#include<stdio.h>
#include<string>
using namespace std;
int main() {
int desk[][4] = { { 2, 3, 4, 4 }, { 3, 4, 6, 6 }, { 4, 6, 8, 8 }, { 4, 6,
8, 8 } };
int n;
scanf("%d", &n);
string str;
getline(cin, str);
char c, c1;
int x, y;
for (int i = 0; i < n; i++) {
scanf("%c%c", &c, &c1);
x = (c - 'a') > 3 ? 7 - (c - 'a') : (c - 'a');
y = (c1 - '1') > 3 ? 7 - (c1 - '1') : (c1 - '1');
printf("%d\n", desk[x][y]);
getline(cin, str);
}
return 0;
}