#include <bits/stdc++.h>
using namespace std;
int advanceMask(int i, vector<string>& a, int nm, int n) {
  nm >>= 4;
  for (int k = 0; k < (int)(4); ++k) {
    if (i + 2 >= n || a[k][i + 2] == '.') nm += (1 << (8 + k));
  }
  return nm;
}
int main() {
  int n;
  cin >> n;
  vector<long long> c(4);
  for (int i = 0; i < (int)(4); ++i) cin >> c[i];
  vector<string> a(4);
  for (int i = 0; i < (int)(4); ++i) cin >> a[i];
  vector<vector<vector<long long>>> dp(
      n + 1,
      vector<vector<long long>>(4, vector<long long>(1 << 12, 1000000000)));
  dp[n][0][(1 << 12) - 1] = 0;
  for (int i = (n)-1; i >= 0; --i)
    for (int j = (4) - 1; j >= 0; --j)
      for (int m = 0; m < (int)((1 << 12)); ++m) {
        int ni = i, nj = j + 1, nm = m;
        if (nj == 4) {
          nj = 0;
          ni++;
          nm = advanceMask(ni, a, nm, n);
        }
        if (m & (1 << j)) {
          dp[i][j][m] = min(dp[i][j][m], dp[ni][nj][nm]);
        }
        for (int d = 1; d <= min(4 - j, n - i); d++) {
          if (d == 4) {
            dp[i][j][m] =
                min(dp[i][j][m], dp[i + 1][0][(1 << 12) - 1] + c[d - 1]);
          } else {
            int pm = m;
            for (int x = j; x < j + d; x++) {
              for (int y = 0; y < d; y++) {
                pm |= (1 << (x + 4 * y));
              }
            }
            if (ni > i) pm = advanceMask(ni, a, pm, n);
            dp[i][j][m] = min(dp[i][j][m], dp[ni][nj][pm] + c[d - 1]);
          }
        }
      }
  int sm = 0;
  for (int i = 0; i < (int)(4); ++i)
    for (int j = 0; j < (int)(3); ++j) {
      if (j > n || a[i][j] == '.') sm += (1 << (i + j * 4));
    }
  cout << dp[0][0][sm] << endl;
}
