#include <bits/stdc++.h>
using namespace std;
const int N = 1005, M = (1 << 16) - 1;
int n, S, inf;
int a[10], b[N], f[N][M + 7], Mk[4][4];
char s[4][N];
void make(int l, int x) {
  Mk[x][l] = M;
  for (int i = 0; i < x; i++)
    for (int j = 0; j < x; j++) Mk[x][l] ^= 1 << (j * 4 + l + i);
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= 4; i++) scanf("%d", &a[i]);
  for (int i = 0; i < 4; i++) scanf("%s", s[i] + 1);
  for (int i = 1; i <= n; i++)
    for (int j = 0; j < 4; j++)
      if (s[j][i] == '*') b[i] |= 1 << j;
  memset(f, 60, sizeof f);
  inf = f[0][0];
  for (int i = 1; i <= 4; i++) {
    for (int j = 0; i + j <= 4; j++) make(j, i);
  }
  for (int i = 0; i < 4; i++) S |= b[i + 1] << (i * 4);
  f[1][S] = 0;
  for (int i = 1; i <= n; i++) {
    for (int S = M; ~S; S--)
      if (f[i][S] != inf) {
        if ((S & 15) == 0) {
          int SS = (S >> 4) | (b[i + 4] << 12);
          f[i + 1][SS] = min(f[i + 1][SS], f[i][S]);
        }
        for (int j = 1; j <= 4 && i + j <= n + 1; j++) {
          for (int k = 0; j + k <= 4; k++) {
            int SS = S & Mk[j][k];
            f[i][SS] = min(f[i][SS], f[i][S] + a[j]);
          }
        }
      }
  }
  printf("%d\n", f[n + 1][0]);
}
