#include <iostream>
#include <algorithm>
#include <map>
#include <cstdio>

using namespace std;

typedef pair<int, int> P;

int n, p, q;
char s, t, b;
double dp[16][3][3];
map<char, P> mpp;
int xdir[4] = {0, 1, 0, -1}, ydir[4] = {1, 0, -1, 0};

void init()
{
  for(int i = 0; i < 3; ++i)
    for(int j = 0; j < 3; ++j)
      mpp[(char)('A'+3*i+j)] = P(i, j);

  return ;
}

void solve()
{
  for(;n; --n)
    for(int i = 0; i < 3; ++i)
      for(int j = 0; j < 3; ++j)
	for(int k = 0; k < 4; ++k){
	  int dy = i+ydir[k], dx = j+xdir[k];
	  if(!(0 <= dx && dx <= 2 && 0 <= dy && dy <= 2) 
	     || (dy == p && dx == q)){ dy = i; dx = j;}
	  dp[n-1][dy][dx] += dp[n][i][j]/4.0;
	}
  
  return ;
}

int main()
{
  init();
  while(cin>>n && n){
    cin >> s >> t >> b;
    fill(&dp[0][0][0], &dp[16][0][0], 0.0);
    p = mpp[s].first; q = mpp[s].second;
    dp[n][p][q] = 1.0;
    p = mpp[b].first; q = mpp[b].second;
    solve();
    p = mpp[t].first; q = mpp[t].second;

    printf("%.8lf\n", dp[0][p][q]);
  }

  return 0;
}