#include <bits/stdc++.h>
using namespace std;
const long long BIG = 1000000000000000000LL;
void solve();
signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  solve();
  return 0;
}
const long long borne = 1010;
long long nbCol;
long long prix[4];
bool doitTuer[borne][4];
long long dp[borne][16][16][16];
long long base[borne];
long long calc(long long col, long long m0, long long m1, long long m2) {
  long long &rep = dp[col][m0][m1][m2];
  if (rep != -1) return rep;
  rep = BIG;
  rep = calc(col + 4, base[col + 4], base[col + 5], base[col + 6]) + prix[3];
  if (m0 == 15) rep = min(rep, (dp[col + 1][m1][m2][base[col + 3]]));
  rep = min(rep, (calc(col, m0 | 1, m1, m2) + prix[0]));
  rep = min(rep, (calc(col, m0 | 3, m1 | 3, m2) + prix[1]));
  rep = min(rep, (calc(col, m0 | 7, m1 | 7, m2 | 7) + prix[2]));
  rep = min(rep, (calc(col, m0 | 2, m1, m2) + prix[0]));
  rep = min(rep, (calc(col, m0 | 6, m1 | 6, m2) + prix[1]));
  rep = min(rep, (calc(col, m0 | 14, m1 | 14, m2 | 14) + prix[2]));
  rep = min(rep, (calc(col, m0 | 4, m1, m2) + prix[0]));
  rep = min(rep, (calc(col, m0 | 12, m1 | 12, m2) + prix[1]));
  rep = min(rep, (calc(col, m0 | 8, m1, m2) + prix[0]));
  return rep;
}
void solve() {
  cin >> nbCol;
  for (long long i = (0); i < (4); ++i) cin >> prix[i];
  for (long long iLig = (0); iLig < (4); ++iLig) {
    for (long long iCol = (0); iCol < (nbCol); ++iCol) {
      char c;
      cin >> c;
      if (c == '*') doitTuer[iCol][iLig] = true;
    }
  }
  for (long long iCol = (0); iCol < (nbCol + 8); ++iCol) {
    for (long long iLig = (0); iLig < (4); ++iLig)
      if (!doitTuer[iCol][iLig]) base[iCol] |= (1LL << iLig);
  }
  for (long long iCol = (0); iCol < (nbCol); ++iCol)
    for (long long m0 = (0); m0 < (16); ++m0)
      for (long long m1 = (0); m1 < (16); ++m1)
        for (long long m2 = (0); m2 < (16); ++m2) dp[iCol][m0][m1][m2] = -1;
  for (long long iCol = (nbCol - 1); iCol >= (0); --iCol)
    for (long long m0 = (0); m0 < (16); ++m0)
      for (long long m1 = (0); m1 < (16); ++m1)
        for (long long m2 = (0); m2 < (16); ++m2) calc(iCol, m0, m1, m2);
  cout << calc(0, base[0], base[1], base[2]) << "\n";
}
