#include <bits/stdc++.h>
using namespace std;
const int N = 1010, inf = 0x3f3f3f3f;
inline int read() {
  register int x = 0, f = 0;
  register char c = getchar();
  while (c < '0' || c > '9') f |= c == '-', c = getchar();
  while (c >= '0' && c <= '9') x = (x << 3) + (x << 1) + c - '0', c = getchar();
  return f ? -x : x;
}
int n;
int w[20], f[N], mx[20][20], m[20][20], dp[N][1 << 16 | 1];
int main() {
  n = read();
  for (int i = 1; i <= 4; ++i) w[i] = read();
  for (int i = 0; i < 4; ++i)
    for (int j = 0; j < n; ++j) {
      char c;
      cin >> c;
      f[j] <<= 1;
      if (c == '*') f[j]++;
    }
  for (int i = 0; i < 4; ++i)
    for (int j = 1; j <= 4 - i; ++j) {
      for (int k = 0; k < 4; ++k)
        for (int p = 0; p < 4; ++p) m[k][p] = 1;
      for (int k = 0; k < j; ++k)
        for (int p = 0; p < j; p++) m[k][i + p] = 0;
      int now = 0;
      for (int k = 3; k >= 0; k--)
        for (int p = 0; p < 4; p++) now = (now << 1) + m[k][p];
      mx[i][j] = now;
    }
  memset(dp, 0x3f, sizeof dp);
  int pos = 0;
  for (int i = 3; i >= 0; i--) pos <<= 4, pos += f[i];
  dp[0][pos] = 0;
  for (int i = 0; i <= n; ++i)
    for (int j = (1 << 16) - 1; ~j; --j) {
      if (dp[i][j] >= inf - 10) continue;
      if (!(j & 15)) {
        int now = (f[i + 4] << 12) | (j >> 4);
        dp[i + 1][now] = min(dp[i][j], dp[i + 1][now]);
      }
      for (int k = 0; k < 4; ++k)
        for (int p = 1; p <= 4 - k; ++p)
          dp[i][j & mx[k][p]] = min(dp[i][j & mx[k][p]], dp[i][j] + w[p]);
    }
  cout << dp[n][0] << '\n';
  return 0;
}
