#include <bits/stdc++.h>
using namespace std;
double dp[16][9];
void room(char c, int &x) {
  switch (c) {
    case 'A':
      x = 0;
      break;
    case 'B':
      x = 1;
      break;
    case 'C':
      x = 2;
      break;
    case 'D':
      x = 3;
      break;
    case 'E':
      x = 4;
      break;
    case 'F':
      x = 5;
      break;
    case 'G':
      x = 6;
      break;
    case 'H':
      x = 7;
      break;
    case 'I':
      x = 8;
      break;
    default:
      break;
  }
}
int main() {
  int n;
  while (cin >> n && n) {
    char s, t, b;
    cin >> s >> t >> b;
    int sr, tr, br;
    room(s, sr);
    room(t, tr);
    room(b, br);
    for (int i = 0; i <= n; ++i) {
      for (int j = 0; j < 9; ++j) {
        dp[i][j] = 0;
      }
    }
    dp[0][sr] = 1;
    for (int i = 1; i <= n; ++i) {
      for (int j = 0; j < 9; ++j) {
        if (j % 3 != 0) {
          if (j - 1 != br) {
            dp[i][j] += dp[i - 1][j - 1] / 4;
          } else {
            dp[i][j] += dp[i - 1][j] / 4;
          }
        }
        if (j >= 3) {
          if (j - 3 != br) {
            dp[i][j] += dp[i - 1][j - 3] / 4;
          } else {
            dp[i][j] += dp[i - 1][j] / 4;
          }
        }
        if (j % 3 != 2) {
          if (j + 1 != br) {
            dp[i][j] += dp[i - 1][j + 1] / 4;
          } else {
            dp[i][j] += dp[i - 1][j] / 4;
          }
        }
        if (j <= 5) {
          if (j + 3 != br) {
            dp[i][j] += dp[i - 1][j + 3] / 4;
          } else {
            dp[i][j] += dp[i - 1][j] / 4;
          }
        }
      }
    }
    printf("%.8f\n", dp[n][tr]);
  }
  return 0;
}
