#include <bits/stdc++.h>
using namespace std;
const int inf = (int)1e9 + 7;
const int N = (int)2e5 + 7;
int n;
int cost[5];
int mask[1001];
int d[1001][(1 << 12)];
char b[5][1001], a[1001][5];
vector<int> masks[4];
int isok(int x) {
  return !((x >> 0) & 1) && !((x >> 1) & 1) && !((x >> 2) & 1) &&
         !((x >> 3) & 1);
}
int main() {
  cin >> n;
  for (int i = 1; i <= 4; ++i) {
    cin >> cost[i];
  }
  for (int i = 0; i < 12; ++i) {
    masks[1].push_back((1 << i));
  }
  masks[2].push_back((1 << 0) + (1 << 1) + (1 << 4) + (1 << 5));
  masks[2].push_back((1 << 1) + (1 << 2) + (1 << 5) + (1 << 6));
  masks[2].push_back((1 << 2) + (1 << 3) + (1 << 6) + (1 << 7));
  masks[2].push_back((1 << 4) + (1 << 5) + (1 << 8) + (1 << 9));
  masks[2].push_back((1 << 5) + (1 << 6) + (1 << 9) + (1 << 10));
  masks[2].push_back((1 << 6) + (1 << 7) + (1 << 10) + (1 << 11));
  masks[3].push_back((1 << 0) + (1 << 1) + (1 << 2) + (1 << 4) + (1 << 5) +
                     (1 << 6) + (1 << 8) + (1 << 9) + (1 << 10));
  masks[3].push_back((1 << 1) + (1 << 2) + (1 << 3) + (1 << 5) + (1 << 6) +
                     (1 << 7) + (1 << 9) + (1 << 10) + (1 << 11));
  for (int i = 1; i <= 3; ++i) {
    for (int &j : masks[i]) {
      j ^= ((1 << 12) - 1);
    }
  }
  for (int i = 0; i < 4; ++i) {
    for (int j = 0; j < n; ++j) {
      cin >> b[i][j];
    }
  }
  for (int i = 0; i < 4; ++i) {
    for (int j = 0; j < n; ++j) {
      a[j][i] = b[i][j];
    }
  }
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < 4; ++j) {
      mask[i] += (1 << j) * (a[i][j] == '*');
    }
  }
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < (1 << 12); ++j) {
      d[i][j] = inf;
    }
  }
  d[0][mask[0] | (mask[1] << 4) | (mask[2] << 8)] = 0;
  for (int i = 0; i + 2 < n; ++i) {
    for (int j = (1 << 12) - 1; j >= 0; --j) {
      if (d[i][j] == inf) {
        continue;
      }
      if (i + 1 + 2 < n) {
        d[i + 1][0] = min(d[i + 1][0], d[i][j] + cost[4]);
      }
      if (isok(j) && i + 3 < n) {
        d[i + 1][(j >> 4) | (mask[i + 3] << 8)] =
            min(d[i + 1][(j >> 4) | (mask[i + 3] << 8)], d[i][j]);
      }
      for (int l = 1; l <= 3; ++l) {
        for (int f : masks[l]) {
          d[i][j & f] = min(d[i][j & f], d[i][j] + cost[l]);
        }
      }
    }
  }
  cout << d[n - 3][0];
  return 0;
}
