#include <bits/stdc++.h>
using namespace std;
template <class T>
inline bool chkmin(T& x, T y) {
  return x > y ? x = y, true : false;
}
template <class T>
inline bool chkmax(T& x, T y) {
  return x < y ? x = y, true : false;
}
inline long long read(void) {
  long long x, f = 1;
  char ch = getchar();
  for (; !isdigit(ch); ch = getchar())
    if (ch == '-') f = -1;
  for (x = 0; isdigit(ch); ch = getchar()) x = x * 10 + ch - '0';
  return x * f;
}
vector<int> V[4];
char str1[5][1010], str[1010][5];
int n, w[5], p[1010], f[1010][1 << 12];
void pre() {
  for (int i = 1; i <= 3; ++i)
    for (int j = 1; j <= 3; ++j)
      for (int z = 1; z <= 4; ++z) {
        if (j + i - 1 > 3 || z + i - 1 > 4) continue;
        int mask = (1 << 12) - 1;
        for (int i1 = j; i1 <= j + i - 1; ++i1)
          for (int j1 = z; j1 <= z + i - 1; ++j1) {
            mask ^= 1 << ((i1 - 1) * 4 + j1 - 1);
          }
        V[i].push_back(mask);
      }
}
int getrow(int x) {
  int ret = 0;
  for (int i = 1; i <= 4; ++i) ret |= (1 << i - 1) * (str[x][i] == '*' ? 1 : 0);
  return ret;
}
int main(void) {
  pre();
  n = read();
  for (int i = 1; i <= 4; ++i) w[i] = read();
  for (int i = 1; i <= 4; ++i) scanf("%s", str1[i] + 1);
  for (int i = 1; i <= n; ++i)
    for (int j = 1; j <= 4; ++j) str[i][j] = str1[j][i];
  memset(f, 0x3f3f3f3f, sizeof(f));
  for (int i = 1; i <= n; ++i) p[i] = getrow(i);
  f[1][(p[3] << 8) | (p[2] << 4) | p[1]] = 0;
  for (int i = 1; i <= n; ++i) {
    for (int j = ((1 << 12) - 1); j >= 0; --j) {
      if ((j & 15) == 0) chkmin(f[i + 1][(j >> 4) | (p[i + 3] << 8)], f[i][j]);
      for (int z = 1; z <= 3; ++z)
        for (auto x : V[z]) chkmin(f[i][j & x], f[i][j] + w[z]);
      chkmin(f[i + 1][0], f[i][j] + w[4]);
    }
  }
  printf("%d\n", f[n][0]);
  return 0;
}
