#include <bits/stdc++.h>
using namespace std;
using LL = long long;
using VI = vector<int>;
using pii = pair<int, int>;
void smin(int& a, const int b) {
  if (a > b) a = b;
}
int pw[20];
int get(int a, int b, int c, int d) { return pw[a] | pw[b] | pw[c] | pw[d]; }
int a[10];
int dp[1111][1 << 12];
char s[4][1111];
int main() {
  for (int i = 0; i < 20; i++) pw[i] = 1 << i;
  const int x = get(0, 3, 6, 9), mask = (1 << 12) - 1, inf = 0x3f3f3f3f;
  const int b[] = {0, 1, pw[0] | pw[1] | pw[3] | pw[4], pw[9] - 1};
  memset(dp, 0x3f, sizeof dp);
  int n;
  cin >> n >> a[1] >> a[2] >> a[3] >> a[4];
  for (int i = 0; i < 4; i++) scanf("%s", s + i);
  dp[0][0] = 0;
  int bit = 0;
  for (int i = 0; i < 4; i++)
    for (int j = 0; j < 3; j++)
      if (s[i][j] == '*') bit |= pw[i * 3 + j];
  dp[2][bit] = 0;
  for (int i = bit; i; i = (i - 1) & bit) {
    for (int j = 1; j < 4; j++) {
      for (int k = 0; k + j <= 4; k++)
        for (int l = 0; l + j <= 3; l++)
          smin(dp[2][i & (mask ^ (b[j] << (k * 3 + l)))], dp[2][i] + a[j]);
    }
  }
  for (int i = 2; i < n; i++) {
    int bit = 0;
    int nxt = 0;
    for (int j = 0; j < 4; j++) {
      for (int k = 0; k < 3; k++)
        if (s[j][k + i - 2] == '*') bit |= pw[j * 3 + k];
      if (s[j][i + 1] == '*') nxt |= pw[j * 3 + 2];
    }
    for (int j = bit;; j = (j - 1) & bit) {
      if (i + 1 < n) smin(dp[i + 1][0], dp[i][j] + a[4]);
      if (!(j & x)) smin(dp[i + 1][(j >> 1) | nxt], dp[i][j]);
      for (int k = 1; k <= 3; k++) {
        for (int l = 0; l + k <= 4; l++)
          for (int m = 0; m + k <= 4; m++) {
            if (m + k < 4) {
              smin(dp[i][j & (mask ^ (b[k] << (l * 3 + m)))], dp[i][j] + a[k]);
              if (!(j & x & (mask ^ (b[k] << (l * 3 + m)))))
                smin(dp[i + 1]
                       [((j & (mask ^ (b[k] << (l * 3 + m)))) >> 1) | nxt],
                     dp[i][j] + a[k]);
            } else if (!(j & x) && i + 1 < n) {
              smin(dp[i + 1]
                     [((j >> 1) | nxt) & (mask ^ (b[k] << (l * 3 + m - 1)))],
                   dp[i][j] + a[k]);
            }
          }
      }
      if (j == 0) break;
    }
  }
  cout << dp[n - 1][0] << endl;
  return 0;
}
