#include <bits/stdc++.h>
using namespace std;
const int maxn = 1010, maxm = 1 << 16, INF = 1e9;
int n, dp[2][maxm], a[5], cMask[maxn];
vector<int> optionalMasks[5];
string s[4];
int addColumn(int column, int mask) {
  return (mask >> 4) | (cMask[column] << 12);
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= 4; i++) scanf("%d", &a[i]);
  for (int i = 0; i < 4; i++) cin >> s[i];
  for (int sz = 1; sz <= 4; sz++) {
    for (int i = 0; i + sz <= 4; i++) {
      int mask = maxm - 1;
      for (int c = 0; c < sz; c++) {
        for (int r = i; r < i + sz; r++) {
          mask ^= 1 << (r + c * 4);
        }
      }
      optionalMasks[sz].push_back(mask);
    }
  }
  for (int i = 0; i < n; i++) {
    int mask = 0;
    for (int j = 0; j < 4; j++) mask |= (s[j][i] == '*') << j;
    cMask[i] = mask;
  }
  for (int i = 0; i < 2; i++)
    for (int j = 0; j < maxm; j++) dp[i][j] = INF;
  int mask = 0, cur = 0;
  for (int i = 0; i < 4; i++) mask = addColumn(i, mask);
  dp[cur][mask] = 0;
  for (int i = 0; i < n; i++) {
    int nxt = !cur;
    for (int j = maxm - 1; j >= 0; j--) {
      if (dp[cur][j] < INF) {
        if (!(j & 15)) {
          int nxtJ = addColumn(i + 4, j);
          dp[nxt][nxtJ] = min(dp[nxt][nxtJ], dp[cur][j]);
        }
        for (int sz = 1; sz <= 4 && i + sz <= n; sz++) {
          for (int k = 0; k < optionalMasks[sz].size(); k++) {
            int nxtJ = j & optionalMasks[sz][k];
            dp[cur][nxtJ] = min(dp[cur][nxtJ], dp[cur][j] + a[sz]);
          }
        }
      }
      dp[cur][j] = INF;
    }
    cur = !cur;
  }
  printf("%d\n", dp[cur][0]);
  return 0;
}
