#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e3 + 7;
const int mst = (1 << 16);
char str[4][maxn];
int col[maxn], rec[4][4], dp[maxn][mst], a[5];
inline void outb(long long x) {
  long long bin[64], sz = 0;
  memset(bin, 0, sizeof(bin));
  for (long long i = 1; i <= x; i <<= 1LL)
    if (x & i)
      bin[sz++] = 1;
    else
      bin[sz++] = 0;
  reverse(bin, bin + 16);
  for (int i = 0; i < 16; ++i) printf("%I64d", bin[i]);
  puts("");
}
void init() {
  memset(col, 0, sizeof(col));
  memset(dp, -1, sizeof(dp));
  for (int i = 0; i < 4; ++i) {
    for (int j = 0; j < 4; ++j) {
      int ret = 0;
      for (int k = 0; k <= j; ++k) ret = (ret << 1) | 1;
      ret <<= (3 - j);
      for (int k = 0; k <= j; ++k) rec[i][j] = ((rec[i][j] << 4) | (ret >> i));
      rec[i][j] <<= (3 - j) * 4;
      rec[i][j] ^= (mst - 1);
    }
  }
}
int main() {
  int n, ret = 0;
  init();
  scanf("%d", &n);
  for (int i = 0; i < 4; ++i) scanf("%d", &a[i]);
  for (int i = 0; i < 4; ++i) scanf("%s", str[i]);
  for (int i = 0; i < n; ++i)
    for (int j = 0; j < 4; ++j)
      col[i] = ((col[i] << 1) | (str[j][i] == '*' ? 1 : 0));
  for (int i = 0; i < 4; ++i) ret = ((ret << 4) | col[i]);
  dp[0][ret] = 0;
  for (int i = 0; i < n; ++i) {
    for (int st = mst - 1; st >= 0; --st) {
      if (dp[i][st] == -1) continue;
      if (!((st >> 12) & 15)) {
        int S = (col[i + 4] | ((st & ((1 << 12) - 1)) << 4));
        if (dp[i + 1][S] == -1)
          dp[i + 1][S] = dp[i][st];
        else
          dp[i + 1][S] = min(dp[i + 1][S], dp[i][st]);
      }
      for (int j = 0; j < 4; ++j)
        for (int k = 0; k < 4; ++k) {
          if (dp[i][st & rec[k][j]] == -1)
            dp[i][st & rec[k][j]] = dp[i][st] + a[j];
          else
            dp[i][st & rec[k][j]] =
                min(dp[i][st & rec[k][j]], dp[i][st] + a[j]);
        }
    }
  }
  printf("%d\n", dp[n][0]);
  return 0;
}
