#include <bits/stdc++.h>
using namespace std;
template <typename T>
inline T read1() {
  T t = 0;
  char k = getchar();
  bool flag = 0;
  while ('0' > k || k > '9') {
    if (k == '-') flag = 1;
    k = getchar();
  }
  while ('0' <= k && k <= '9')
    t = (t << 3) + (t << 1) + (k ^ 48), k = getchar();
  return flag ? -t : t;
}
int s, x[5], dp[2][16][16][16];
char str[5][1005];
int main() {
  s = read1<long long>();
  for (int i = 1; i < 5; ++i) x[i] = read1<long long>();
  for (int i = 1; i <= 4; ++i) scanf("%s", str[i] + 1);
  memset(dp[0], 0x7f, sizeof(dp[0]));
  dp[0][15][15][15] = 0;
  for (int i = 1; i <= s; ++i) {
    memset(dp[i & 1], 0x7f, sizeof(dp[i & 1]));
    int t = 0;
    for (int j = 1; j < 5; ++j) t = t << 1 | (str[j][i] == '.');
    for (int j = 0; j < 16; ++j)
      for (int k = 0; k < 16; ++k)
        for (int l = 0; l < 16; ++l)
          dp[i & 1][15][15][15] =
              min(dp[i & 1][15][15][15], dp[~i & 1][j][k][l] + x[4]);
    for (int k = 0; k < 16; ++k)
      for (int l = 0; l < 16; ++l)
        dp[i & 1][k][l][t] = min(dp[i & 1][k][l][t], dp[~i & 1][15][k][l]);
    for (int j = 0; j < 16; ++j)
      for (int k = 0; k < 16; ++k)
        for (int r = 0; r < 16; ++r)
          for (int l = 1; l < 4; ++l)
            for (int w = 0; w < 5 - l; ++w) {
              int op[3] = {j, k, r};
              for (int f = 2; f > 2 - l; --f) op[f] |= (1 << l) - 1 << w;
              dp[i & 1][op[0]][op[1]][op[2]] = min(
                  dp[i & 1][op[0]][op[1]][op[2]], dp[i & 1][j][k][r] + x[l]);
            }
  }
  cout << dp[s & 1][15][15][15];
  return 0;
}
