#include <bits/stdc++.h>
using namespace std;
int dx[4] = {0, 1, 0, -1}, dy[4] = {1, 0, -1, 0};
double search(int a[4][4], int n, pair<int, int> p, pair<int, int> q) {
  double b[4][4], c[4][4], m = n;
  fill(&b[0][0], &b[3][3], 0);
  b[p.first][p.second] = 1;
  while (m--) {
    fill(&c[0][0], &c[3][3], 0);
    for (int i = 0; i < 3; i++) {
      for (int j = 0; j < 3; j++) {
        if (b[i][j] != 0) {
          for (int k = 0; k < 4; k++) {
            int s = i + dy[k], t = j + dx[k];
            if (0 <= s && s < 3 && 0 <= t && t < 3) {
              if (a[s][t] != 2) {
                c[s][t] += b[i][j];
              } else {
                c[i][j] += b[i][j];
              }
            }
          }
        }
      }
    }
    for (int i = 0; i < 3; i++) {
      for (int j = 0; j < 3; j++) {
        double t = c[i][j];
        b[i][j] = t;
      }
    }
  }
  return (double)(b[q.first][q.second]) / (1 << (2 * n));
}
pair<int, int> func(string str) {
  if (str == "A") {
    return pair<int, int>(0, 0);
  } else if (str == "B") {
    return pair<int, int>(0, 1);
  } else if (str == "C") {
    return pair<int, int>(0, 2);
  } else if (str == "D") {
    return pair<int, int>(1, 0);
  } else if (str == "E") {
    return pair<int, int>(1, 1);
  } else if (str == "F") {
    return pair<int, int>(1, 2);
  } else if (str == "G") {
    return pair<int, int>(2, 0);
  } else if (str == "H") {
    return pair<int, int>(2, 1);
  } else {
    return pair<int, int>(2, 2);
  }
}
int main() {
  int n, a[4][4];
  string s, t, u;
  pair<int, int> p;
  while (1) {
    cin >> n;
    if (n == 0) {
      break;
    }
    cin >> s >> t >> u;
    fill(&a[0][0], &a[3][3], 0);
    p = func(u);
    a[p.first][p.second] = 2;
    p = func(t);
    a[p.first][p.second] = 1;
    printf("%.8f\n", search(a, n, func(s), p));
  }
  return 0;
}
