#include<iostream>
#include<iomanip>
using namespace std;

#define BLANK 0
#define STORE 1
#define CHARGER 2

int main()
{
  int n;
  char s,t,b;

  cout<<setprecision(8);
  cout<<setiosflags(ios::fixed);

  while(cin>>n,n){
    int room[3+2][3+2]={0};
    double dp[16][3+2][3+2]={0};
    int dx[4]={-1,1,0,0};
    int dy[4]={0,0,-1,1};
    int i,j,y,x;

    cin>>s>>t>>b;
    s-='A';
    t-='A';
    b-='A';
    for(i=0;i<3+2;i++){
      room[0][i]=STORE;
      room[i][0]=STORE;
      room[3+2-1][i]=STORE;
      room[i][3+2-1]=STORE;
    }
    room[(t/3)+1][(t%3)+1]=CHARGER;
    room[(b/3)+1][(b%3)+1]=STORE;
    dp[0][(s/3)+1][(s%3)+1]=1.0;

    for(i=1;i<=n;i++){
      for(y=1;y<=3;y++){
	for(x=1;x<=3;x++){
	  for(j=0;j<4;j++){
	    int yy=y+dy[j],xx=x+dx[j];
	    if(room[yy][xx]==STORE){yy=y;xx=x;}
	    dp[i][yy][xx]+=dp[i-1][y][x]/4.0;
	  }
	}
      }
    }
    cout<<dp[n][(t/3)+1][(t%3)+1]<<endl;
  }
}