#include <bits/stdc++.h>
namespace OI {
template <class T>
void rd(T &x) {
  x = 0;
  int f = 1;
  char c;
  while (!isdigit(c = getchar()))
    if (c == '-') f = -1;
  do {
    x = (x << 3) + (x << 1) + (c ^ 48);
  } while (isdigit(c = getchar()));
  x *= f;
}
template <class T>
void pt(T x) {
  if (x < 0) putchar('-'), x = -x;
  if (x > 9) pt(x / 10);
  putchar(x % 10 ^ 48);
}
}  // namespace OI
using namespace OI;
using namespace std;
const int N = 5, M = 1005, INF = 0x3f3f3f3f;
int n, w[N], maxx[N][N], m[N][N], dp[M][1 << 16], f[M];
int main() {
  rd(n);
  for (int i = 1; i <= 4; i++) rd(w[i]);
  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 h = 0; h < 4; h++) m[k][h] = 1;
      for (int k = 0; k < j; k++)
        for (int h = 0; h < j; h++) m[k][i + h] = 0;
      int now = 0;
      for (int k = 3; k >= 0; k--)
        for (int h = 0; h < 4; h++) now = (now << 1) + m[k][h];
      maxx[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 >= 0; j--) {
      if (dp[i][j] == INF) 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 h = 1; h <= 4 - k; h++)
          dp[i][j & maxx[k][h]] = min(dp[i][j & maxx[k][h]], dp[i][j] + w[h]);
    }
  pt(dp[n][0]);
  return 0;
}
