#include <bits/stdc++.h>
using namespace std;
int n, m;
int inf = (int)1e9;
int c[4];
string t[4];
vector<vector<long long> > dp;
const int hhh = 21;
string z[hhh] = {"000100010001", "100010001000", "000000010001", "000010001000",
                 "001100111111", "001000111111", "000100111111", "000000111111",
                 "100110011111", "000110011111", "100010011111", "000010011111",
                 "110011001111", "010011001111", "100011001111", "000011001111",
                 "000000000001", "000000001000", "000000000000", "000000001111",
                 "000011111111"};
int co[hhh][4] = {{0, 0, 1, 0}, {0, 0, 1, 0}, {1, 0, 1, 0}, {1, 0, 1, 0},
                  {0, 1, 0, 0}, {1, 1, 0, 0}, {1, 1, 0, 0}, {2, 1, 0, 0},
                  {0, 1, 0, 0}, {1, 1, 0, 0}, {1, 1, 0, 0}, {2, 1, 0, 0},
                  {0, 1, 0, 0}, {1, 1, 0, 0}, {1, 1, 0, 0}, {2, 1, 0, 0},
                  {0, 1, 1, 0}, {0, 1, 1, 0}, {0, 0, 2, 0}, {0, 2, 0, 0},
                  {0, 0, 0, 0}};
int ff(string& s) {
  int res = 0;
  for (int i = 11; i >= 0; --i) res = res + res + (s[i] - '0');
  return res;
}
int f(int jj) {
  vector<int> z;
  for (int i = 0; i < 4; ++i) z.push_back(int(t[i][jj] == '*'));
  reverse(z.begin(), z.end());
  int res = 0;
  for (int i = 0; i < z.size(); ++i) res = res + res + z[i];
  return res;
}
void add(int i, int j, int ii, int jj, int cost) {
  dp[i][j] = min(dp[i][j], dp[ii][jj] + cost);
}
void addd(int ii, int mask, int ma, int cost) {
  ma = (mask & ma);
  for (int p = 0; p < 4; ++p)
    if ((ma & (1 << p)) > 0) return;
  ma = (ma >> 4) + (f(ii + 3) << 8);
  add(ii + 1, ma, ii, mask, cost);
}
int main() {
  ios_base::sync_with_stdio(false);
  cin >> n;
  m = (1 << 12);
  for (int i = 0; i < 4; ++i) cin >> c[i];
  for (int i = 2; i >= 0; --i) c[i] = min(c[i], c[i + 1]);
  for (int i = 0; i < 4; ++i) {
    cin >> t[i];
    t[i] += string(3, '.');
  }
  dp.assign(n + 1, vector<long long>(m, inf));
  dp[0][f(0) + (f(1) << 4) + (f(2) << 8)] = 0;
  for (int i = 0; i < n; ++i) {
    for (int mask = 0; mask < m; ++mask) {
      if (dp[i][mask] == inf) continue;
      add(i + 1, 0, i, mask, c[3]);
      for (int s = 0; s < hhh - 1; ++s) {
        int cost = 0;
        for (int o = 0; o < 4; ++o) cost += co[s][o] * c[o];
        addd(i, mask, ff(z[s]), cost);
      }
      int cost = 0;
      for (int p = 0; p < 4; ++p)
        if ((mask & (1 << p)) > 0) cost += c[0];
      addd(i, mask, ff(z[hhh - 1]), cost);
    }
  }
  cout << dp[n][0] << endl;
  return 0;
}
