#include <bits/stdc++.h>
using namespace std;
int n, sx, sy, tx, ty, bx, by;
int mvx[4] = {-1, 1, 0, 0};
int mvy[4] = {0, 0, -1, 1};
int c;
void dfs(int k, int x, int y) {
  if (k == n) {
    if (x == tx && y == ty) {
      c++;
    }
    return;
  }
  for (int i = 0; i < 4; i++) {
    int mx = x + mvx[i];
    int my = y + mvy[i];
    if (mx < 0 || mx > 2 || my < 0 || my > 2 || (mx == bx && my == by)) {
      dfs(k + 1, x, y);
      continue;
    }
    dfs(k + 1, mx, my);
  }
}
int main() {
  char s, t, b;
  map<char, pair<int, int>> rooms;
  rooms['A'].first = 0;
  rooms['A'].second = 0;
  rooms['B'].first = 1;
  rooms['B'].second = 0;
  rooms['C'].first = 2;
  rooms['C'].second = 0;
  rooms['D'].first = 0;
  rooms['D'].second = 1;
  rooms['E'].first = 1;
  rooms['E'].second = 1;
  rooms['F'].first = 2;
  rooms['F'].second = 1;
  rooms['G'].first = 0;
  rooms['G'].second = 2;
  rooms['H'].first = 1;
  rooms['H'].second = 2;
  rooms['I'].first = 2;
  rooms['I'].second = 2;
  while (cin >> n && n) {
    cin >> s >> t >> b;
    c = 0;
    sx = rooms[s].first;
    sy = rooms[s].second;
    tx = rooms[t].first;
    ty = rooms[t].second;
    bx = rooms[b].first;
    by = rooms[b].second;
    dfs(0, sx, sy);
    printf("%.8f\n", (double)c / pow(4, n));
  }
  return 0;
}
