#include <bits/stdc++.h>
using namespace std;
long cnt, as;
char s, t, b;
const int dy[] = {-1, 0, 1, 0};
const int dx[] = {0, 1, 0, -1};
int main() {
  int n, field[2][5][5], tx, ty;
  for (; cin >> n, n;) {
    cin.ignore();
    cnt = as = 0;
    scanf(" %c %c %c ", &s, &t, &b);
    memset(field, 0, sizeof(field));
    int x = s == 'A' || s == 'D' || s == 'G'   ? 1
            : s == 'B' || s == 'E' || s == 'H' ? 2
                                               : 3;
    int y = s == 'A' || s == 'B' || s == 'C'   ? 1
            : s == 'D' || s == 'E' || s == 'F' ? 2
                                               : 3;
    int p = t == 'A' || t == 'D' || t == 'G'   ? 1
            : t == 'B' || t == 'E' || t == 'H' ? 2
                                               : 3;
    int q = t == 'A' || t == 'B' || t == 'C'   ? 1
            : t == 'D' || t == 'E' || t == 'F' ? 2
                                               : 3;
    int u = b == 'A' || b == 'D' || b == 'G'   ? 1
            : b == 'B' || b == 'E' || b == 'H' ? 2
                                               : 3;
    int t = b == 'A' || b == 'B' || b == 'C'   ? 1
            : b == 'D' || b == 'E' || b == 'F' ? 2
                                               : 3;
    field[0][y][x] = 1;
    field[0][0][0] = field[0][0][1] = field[0][0][2] = field[0][0][3] =
        field[0][0][4] = 1;
    field[0][4][0] = field[0][4][1] = field[0][4][2] = field[0][4][3] =
        field[0][4][4] = 1;
    field[0][1][0] = field[0][2][0] = field[0][3][0] = 1;
    field[0][1][4] = field[0][2][4] = field[0][3][4] = 1;
    for (int k = 0; k < n; k++) {
      for (int i = 1; i < 4; i++) {
        for (int j = 1; j < 4; j++) {
          if (i == t && j == u) continue;
          for (int g = 0; g < 4; g++) {
            tx = j + dx[g];
            ty = i + dy[g];
            if (field[0][i][j] == 0 && (tx < 1 || ty < 1 || tx >= 4 || ty >= 4))
              continue;
            field[1][i][j] += field[0][ty][tx];
          }
          if (field[0][i][j] != 0 &&
              (i - 1 == t && j == u || i + 1 == t && j == u ||
               i == t && j - 1 == u || i == t && j + 1 == u)) {
            field[1][i][j]++;
          }
        }
      }
      for (int ii = 1; ii < 4; ii++) {
        for (int jj = 1; jj < 4; jj++) {
          printf("%7d ", field[1][ii][jj]);
        }
        puts("");
      }
      puts("");
      for (int i = 1; i < 4; i++)
        for (int j = 1; j < 4; j++)
          field[0][i][j] = field[1][i][j], field[1][i][j] = 0;
    }
    double ababa = 0.0;
    for (int i = 1; i < 4; i++)
      for (int j = 1; j < 4; j++) ababa += field[0][i][j];
    printf("%.8lf\n", (double)field[0][q][p] / ababa);
  }
  return 0;
}
