#include <bits/stdc++.h>
using namespace std;
const int SIZ = 1007;
const int STA = (1 << 16) - 1;
int N, A[5];
unsigned char S[4][SIZ];
int DP[SIZ][STA + 7], C[SIZ];
vector<int> msk[5];
int trans_msk(int ofs, int len) {
  int msk = 0;
  for (int i = 0; i < len; i++)
    for (int j = 0; j < len; j++) msk |= 1 << ((j << 2) + ofs + i);
  return msk;
}
int col_msk(int ofs) {
  int msk = 0;
  for (int j = 0; j < 4; j++) msk |= S[j][ofs] << j;
  return msk;
}
void init() {
  for (int i = 1; i <= 4; i++) {
    for (int j = 0; j + i <= 4; j++) {
      msk[i].push_back(STA ^ trans_msk(j, i));
    }
  }
  for (int i = 0; i < N; i++) C[i] = col_msk(i);
}
int main() {
  scanf("%d", &N);
  for (int i = 1; i <= 4; i++) scanf("%d", &A[i]);
  char buf[SIZ];
  for (int i = 0; i < 4; i++) {
    scanf("%s", buf);
    for (int j = 0; j < N; j++) S[i][j] = (buf[j] == '*');
  }
  init();
  memset(DP, 0x3f, sizeof(DP));
  int S = 0;
  for (int i = 0; i < min(4, N); i++) S |= C[i] << (i << 2);
  DP[0][S] = 0;
  for (int i = 0; i < N; i++) {
    for (int S = STA; S >= 0; S--) {
      if (DP[i][S] == 0x3f3f3f3f) continue;
      if ((S & 15) == 0) {
        int SS = S >> 4 | (C[i + 4] << 12);
        DP[i + 1][SS] = min(DP[i + 1][SS], DP[i][S]);
      }
      for (int j = 1; j <= 4 && i + j <= N; j++) {
        for (auto SS : msk[j]) {
          DP[i][S & SS] = min(DP[i][S & SS], DP[i][S] + A[j]);
        }
      }
    }
  }
  printf("%d\n", DP[N][0]);
}
