#include <bits/stdc++.h>
using namespace std;
const int maxn = 1010;
const int maxs = 1 << 13;
const int INF = 0x3f3f3f3f;
int dp[maxn][5][maxs];
int n;
int a[5];
char matrix[maxn][4];
int stat[maxn][4], stat2[maxn][4];
int top[13];
void read() {
  cin >> n;
  a[0] = 0;
  cin >> a[1] >> a[2] >> a[3] >> a[4];
  for (int i = 1; i <= 4; i++) {
    for (int j = 1; j <= n; j++) {
      cin >> matrix[j][i];
    }
  }
}
void init() {
  for (int i = 1; i <= 12; i++) top[i] = top[i - 1] + (1 << (12 - i));
  memset(dp, 0x3f3f3f3f, sizeof(dp));
  dp[0][4][(1 << 12) - 1] = 0;
}
void decode(int i, int j, int state) {
  stat[i][j] = stat2[i][j] = (matrix[i][j] == '.' ? 1 : 0);
  int curx = i, cury = j;
  for (int k = 1; k <= 12; k++) {
    cury--;
    if (cury == 0) curx -= 1, cury = 4;
    if (curx <= 0) break;
    stat[curx][cury] = (state & 1);
    stat2[curx][cury] = stat[curx][cury];
    state >>= 1;
  }
}
int encode(int i, int j) {
  int ret = 0;
  int curx = i, cury = j;
  for (int k = 1; k <= 12; k++) {
    if (curx > 0)
      ret = ret + stat2[curx][cury] * (1 << (k - 1));
    else {
      ret += top[12 - k + 1];
      break;
    }
    cury--;
    if (cury == 0) curx -= 1, cury = 4;
  }
  return ret;
}
void print() {
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= 4; j++) cout << stat2[i][j];
    cout << endl;
  }
  cout << endl;
}
void calc(int i, int j) {
  for (int k = 0; k < (1 << 12); k++) {
    int cur;
    if (j > 1)
      cur = dp[i][j - 1][k];
    else
      cur = dp[i - 1][4][k];
    if (cur == INF) continue;
    decode(i, j, k);
    if ((k & top[5 - j]) ^ top[5 - j]) continue;
    int maxc = min(i, j);
    for (int t = 0; t <= maxc && t < 4; t++) {
      if (t == 1)
        stat2[i][j] = 1;
      else if (t == 2) {
        stat2[i][j] = 1;
        stat2[i][j - 1] = 1;
        stat2[i - 1][j] = 1;
        stat2[i - 1][j - 1] = 1;
      } else if (t == 3) {
        stat2[i][j] = 1;
        stat2[i][j - 1] = 1;
        stat2[i][j - 2] = 1;
        stat2[i - 1][j] = 1;
        stat2[i - 1][j - 1] = 1;
        stat2[i - 1][j - 2] = 1;
        stat2[i - 2][j] = 1;
        stat2[i - 2][j - 1] = 1;
        stat2[i - 2][j - 2] = 1;
      }
      int curstate = (t ? encode(i, j) : ((((k ^ top[1]) << 1) | stat[i][j])));
      dp[i][j][curstate] = min(dp[i][j][curstate], cur + a[t]);
      for (int u = i; u >= i - t + 1; u--) {
        for (int v = j; v >= j - t + 1; v--) {
          stat2[u][v] = stat[u][v];
        }
      }
    }
    if (j == 4 && i >= 3 && i + 1 <= n) {
      dp[i + 1][j][(1 << 12) - 1] =
          min(dp[i + 1][j][(1 << 12) - 1],
              min(cur, dp[i][j][(1 << 12) - 1]) + a[4]);
    }
  }
}
void solve() {
  init();
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= 4; j++) {
      calc(i, j);
    }
  }
  printf("%d\n", dp[n][4][(1 << 12) - 1]);
}
int main() {
  read();
  solve();
  return 0;
}
