#include <bits/stdc++.h>
using namespace std;
vector<long long> sb(5);
vector<int> a(5);
vector<vector<long long>> inp(0);
vector<vector<long long>> dp(0);
void itoi(int x) { cout << bitset<12>(x); }
int main() {
  sb[0] = 0;
  sb[1] = 1 << 11;
  sb[2] = sb[1] + (1 << 10) + (1 << 7) + (1 << 6);
  sb[3] = sb[2] + (1 << 9) + (1 << 5) + (1 << 3) + (1 << 2) + (1 << 1);
  sb[4] = (1 << 16) - 1;
  for (int i = 1; i < 4; i++) sb[i] = sb[i] << 4;
  long long n;
  cin >> n;
  a[0] = 0;
  for (int i = 1; i < 5; i++) cin >> a[i];
  inp.resize(n + 8, vector<long long>(4, 1));
  for (long long i = 0; i < 4; i++) {
    string s;
    cin >> s;
    for (long long j = 0; j < n; j++)
      if (s[j] == '*') inp[j][i] = 0;
  }
  dp.resize(n + 8, vector<long long>((1 << 12), -1));
  long long f_p = 0;
  for (int i = 0; i < 3; i++) {
    for (int j = 0; j < 4; j++) {
      f_p = f_p << 1;
      f_p += inp[i][j];
    }
  }
  dp[0][f_p] = 0;
  for (int i = 0; i <= n; i++) {
    for (int p = 0; p < (1 << 12); p++) {
      if (dp[i][p] == -1) continue;
      long long p_nn = p;
      for (int k = 0; k < 4; k++) {
        p_nn = p_nn << 1;
        p_nn += inp[i + 3][k];
      }
      for (int d1 = 0; d1 < 5; d1++) {
        for (int d2 = 0; d2 < 4; d2++) {
          for (int d3 = 0; d3 < 3; d3++) {
            for (int d4 = 0; d4 < 2; d4++) {
              long long p_n = p_nn;
              p_n = p_n | sb[d1];
              p_n = p_n | (sb[d2] >> 1);
              p_n = p_n | (sb[d3] >> 2);
              p_n = p_n | (sb[d4] >> 3);
              if ((p_n >> 12) != 15) continue;
              p_n = p_n & ((1 << 12) - 1);
              long long c = dp[i][p] + a[d1] + a[d2] + a[d3] + a[d4];
              if (dp[i + 1][p_n] == -1) {
                dp[i + 1][p_n] = c;
              } else {
                dp[i + 1][p_n] = min(dp[i + 1][p_n], c);
              }
            }
          }
        }
      }
    }
  }
  cout << dp[n + 1][(1 << 12) - 1];
  return 0;
}
