#include <bits/stdc++.h>
int first_x, first_y;
int zyuden_x, zyuden_y;
int soko_x, soko_y;
double map[15][5][5];
void get_where(int* x, int* y, char c) {
  if (c == 'A') {
    *x = 1;
    *y = 1;
  }
  if (c == 'B') {
    *x = 2;
    *y = 1;
  }
  if (c == 'C') {
    *x = 3;
    *y = 1;
  }
  if (c == 'D') {
    *x = 1;
    *y = 2;
  }
  if (c == 'E') {
    *x = 2;
    *y = 2;
  }
  if (c == 'F') {
    *x = 3;
    *y = 2;
  }
  if (c == 'G') {
    *x = 1;
    *y = 3;
  }
  if (c == 'H') {
    *x = 2;
    *y = 3;
  }
  if (c == 'I') {
    *x = 3;
    *y = 3;
  }
}
int main(void) {
  int battery;
  char first[2], zyuden[2], soko[2];
  int i, j, k;
  while (1) {
    scanf("%d", &battery);
    if (battery == 0) break;
    scanf("%s%s%s", first, zyuden, soko);
    get_where(&first_x, &first_y, first[0]);
    get_where(&zyuden_x, &zyuden_y, zyuden[0]);
    get_where(&soko_x, &soko_y, soko[0]);
    memset(map, 0, sizeof(map));
    map[0][first_x][first_y] = 1;
    for (i = 1; i <= battery; i++) {
      for (j = 1; j <= 3; j++) {
        for (k = 1; k <= 3; k++) {
          map[i][j][k] = (map[i - 1][j - 1][k] + map[i - 1][j + 1][k] +
                          map[i - 1][j][k - 1] + map[i - 1][j][k + 1]) /
                         4.0;
          if (j == soko_x && k == soko_y) map[i][j][k] = 0;
        }
      }
    }
    printf("%.15f\n", map[battery][zyuden_x][zyuden_y]);
  }
  return 0;
}
