#include <bits/stdc++.h>
template <typename T>
void FILL_(void* ptr, size_t size, T value) {
  std::fill((T*)ptr, (T*)ptr + size, value);
}
using namespace std;
double dp[15 + 1][9];
int dir[4] = {-3, -1, 1, 3};
int main(void) {
  int n;
  while (cin >> n && n) {
    FILL_((dp), sizeof(dp) / sizeof(0), (0));
    char tmp;
    int s, t, b;
    cin >> tmp;
    s = (int)(tmp - 'A');
    cin >> tmp;
    t = (int)(tmp - 'A');
    cin >> tmp;
    b = (int)(tmp - 'A');
    dp[0][s] = 1;
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < 9; j++) {
        if (dp[i][j] == 0) continue;
        for (int k = 0; k < 4; k++) {
          if (0 <= j + dir[k] && j + dir[k] < 9 && j + dir[k] != b) {
            dp[i + 1][j + dir[k]] += dp[i][j] * 0.25;
          } else {
            dp[i + 1][j] += dp[i][j] * 0.25;
          }
        }
      }
    }
    printf("%.8lf\n", dp[n][t]);
  }
}
