#include <bits/stdc++.h>
using namespace std;
int p[4];
vector<int> b(4);
string s[4];
map<vector<int>, int> DP;
const int INF = 1e9 + 8;
bool operator<(vector<int> &a, vector<int> &b) {
  for (int i = 0; i < 4; i++) {
    if (a[i] < b[i]) return true;
    if (a[i] > b[i]) return false;
  }
  return false;
}
bool check(vector<int> &a, int posx, int posy, int siz) {
  int cnt = 0;
  if (posx < 0) return false;
  for (int i = 0; i < siz; i++) {
    if (a[posy + i] > posx + siz - 1) return false;
    if (a[posy + i] < posx) cnt++;
  }
  return cnt < siz;
}
int get_ans(vector<int> a) {
  auto t = DP.find(a);
  if (t != DP.end()) return t->second;
  int mina = INF, maxa = -2;
  for (int i = 0; i < 4; i++) {
    mina = min(mina, a[i]);
    maxa = max(maxa, a[i]);
    if (a[i] < -1) return INF;
  }
  DP[a] = INF;
  if (maxa - mina > 4) {
    return INF;
  }
  t = DP.find(a);
  for (int i = 0; i < 4; i++) {
    if (a[i] == -1) continue;
    if (a[i] == mina && maxa - mina == 4) continue;
    if (s[i][a[i]] == '.') {
      --a[i];
      t->second = get_ans(a);
      return t->second;
    }
  }
  for (int i = 0; i < 4; ++i) {
    for (int j = 1; j <= 4 - i; j++) {
      for (int z = 0; z < j; z++) {
        if (check(a, maxa - z, i, j)) {
          for (int k(0); k < 4; k++) b[k] = a[k];
          for (int k = i; k < i + j; k++) {
            b[k] = maxa - z - 1;
          }
          t->second = min(t->second, get_ans(b) + p[j - 1]);
        }
      }
    }
  }
  return t->second;
}
int main() {
  int f;
  cin >> f;
  for (int i(0); i < 4; ++i) cin >> p[i];
  for (int i(2); i >= 0; --i) p[i] = min(p[i], p[i + 1]);
  for (int i(0); i < 4; ++i) cin >> s[i];
  DP[{-1, -1, -1, -1}] = 0;
  f--;
  cout << get_ans({f, f, f, f});
  return 0;
}
