/*
Name: Wenyu Cao Phillips Academy
Senior Div
Grade: 10
ACSL CONTEST #4
*/
#include <cstdio>
#include <iostream>
#include <cstdlib>
#include <algorithm>
#include <cstring>
#include <sstream>
#include <string>
#include <cctype>
using namespace std;
int board[10][10],L,mp[299];
int dx[]={-1,-1,-1,0,0,1,1,1};
int dy[]={-1,0,1,-1,1,-1,0,1};
char str[99999];
inline bool valid(int x,int y) {return (x>=1 &&
x<=8 && y>=1 && y<=8);}
inline void reset() {
memset(board,0,sizeof(board));
board[5][4]=board[4][5]=1;
board[4][4]=board[5][5]=2;
}
void disp() {
for(int
i=1;i<=8;i++) {
for(int j=1;j<=8;j++) {
cout << board[i][j];
}
cout << endl;
}
}
int solve() {
L=strlen(str);
for(int
i='A';i<='H';i++) {mp[i]=(i-'A'+1);}
string
order="";
for(int
i=0;i<L;i++) {
if (isdigit(str[i]) ||
isupper(str[i]) || str[i]=='#') {order+=str[i];}
else {order+=' ';}
}
istringstream
in(order);
string s;
int ans=0;
int
player=1;
while (1) {
in >> s;
if (s[0]=='#') {return ans;}
else {
int x=s[0]-'0';
int y=mp[s[1]];
board[x][y]=player;
for(int i=0;i<8;i++) {
int
r=x+dx[i],c=y+dy[i];
if
(valid(r,c) && board[r][c]+player==3) {
while (valid(r,c) && board[r][c]+player==3)
{r+=dx[i];c+=dy[i];}
if (valid(r,c) && board[r][c]==player) {
int
xx=x+dx[i];
int
yy=y+dy[i];
while
(make_pair(xx,yy)!=make_pair(r,c)) {
ans++;
board[xx][yy]=player;
xx+=dx[i];
yy+=dy[i];
}
}
}
}
}
player=(player==1 ? 2 : 1);
}
}
int main() {
int five=5;
while
(five--) {
reset();
fgets(str,99999,stdin);
cout << solve() << endl;
}
system("PAUSE");
return 0;
}