#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);
    cout << sr << " " << tr << " " << br << "\n";
    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 != br) {
          switch (j) {
            case 0:
              dp[i][j] +=
                  (dp[i - 1][1] / 2 + dp[i - 1][3] / 2 + dp[i - 1][0]) / 2;
              break;
            case 1:
              dp[i][j] +=
                  (dp[i - 1][0] + dp[i - 1][4] + dp[i - 1][2] + dp[i - 1][1]) /
                  4;
              break;
            case 2:
              dp[i][j] +=
                  (dp[i - 1][1] / 2 + dp[i - 1][5] / 2 + dp[i - 1][2]) / 2;
              break;
            case 3:
              dp[i][j] +=
                  (dp[i - 1][0] + dp[i - 1][4] + dp[i - 1][6] + dp[i - 1][3]) /
                  4;
              break;
            case 4:
              dp[i][j] +=
                  (dp[i - 1][1] + dp[i - 1][5] + dp[i - 1][7] + dp[i - 1][3]) /
                  4;
              break;
            case 5:
              dp[i][j] +=
                  (dp[i - 1][2] + dp[i - 1][4] + dp[i - 1][8] + dp[i - 1][5]) /
                  4;
              break;
            case 6:
              dp[i][j] +=
                  (dp[i - 1][3] / 2 + dp[i - 1][7] / 2 + dp[i - 1][6]) / 2;
              break;
            case 7:
              dp[i][j] += (dp[i - 1][6] + dp[i - 1][4] / 2 + dp[i - 1][8] / 2 +
                           dp[i - 1][7] / 2) /
                          2;
              break;
            case 8:
              dp[i][j] +=
                  (dp[i - 1][5] / 2 + dp[i - 1][7] / 2 + dp[i - 1][8]) / 2;
              break;
            default:
              break;
          }
        }
      }
    }
    cout << dp[n][tr] << "\n";
  }
  return 0;
}
