#include <bits/stdc++.h>
using namespace std;
int y11(string);
int x11(string);
int main() {
  int n;
  string st, ba, sto;
  int dx[] = {0, 1, 0, -1};
  int dy[] = {1, 0, -1, 0};
  int ma[3][3] = {{0, 0, 0}, {0, 0, 0}, {0, 0, 0}};
  while (true) {
    cin >> n;
    double dp[15][4][4];
    for (int i = 0; i < 15; i++)
      for (int j = 0; j < 4; j++)
        for (int k = 0; k < 4; k++) dp[i][j][k] = 0.0;
    if (n == 0) break;
    cin >> st;
    cin >> ba;
    cin >> sto;
    ma[y11(st)][x11(st)] = 1;
    ma[y11(ba)][x11(ba)] = 9;
    ma[y11(sto)][x11(sto)] = 8;
    int nx, ny;
    dp[n][y11(st)][x11(st)] = 1.0;
    while (true) {
      if (n == 0) break;
      for (int t = 0; t < 2; t++) {
        for (int g = 0; g < 2; g++) {
          for (int i = 0; i < 4; i++) {
            nx = g + dx[i];
            ny = t + dy[i];
            if (nx > 2 || ny > 2 || nx < 0 || ny < 0) continue;
            if (nx == x11(sto) && ny == y11(sto)) {
              nx = g;
              ny = t;
            }
            dp[n - 1][ny][nx] += dp[n][t][g] / 4.0;
          }
        }
      }
      n--;
    }
    printf("%.8f\n", dp[0][y11(ba)][x11(ba)]);
  }
}
int y11(string s) {
  if (s == "A") return 0;
  if (s == "B") return 0;
  if (s == "C") return 0;
  if (s == "D") return 1;
  if (s == "E") return 1;
  if (s == "F") return 1;
  if (s == "G") return 2;
  if (s == "H") return 2;
  if (s == "I") return 2;
  return 9;
}
int x11(string s) {
  if (s == "A") return 0;
  if (s == "B") return 1;
  if (s == "C") return 2;
  if (s == "D") return 0;
  if (s == "E") return 1;
  if (s == "F") return 2;
  if (s == "G") return 0;
  if (s == "H") return 1;
  if (s == "I") return 2;
  return 9;
}
