#include <bits/stdc++.h>
using namespace std;
constexpr int rsz = 5;
constexpr int sz = 1005;
int dp[rsz][sz][rsz][rsz][rsz][rsz], n, cost[rsz];
string s[rsz];
int mxs(const int& r) { return max(0, r - 1); }
int solve(int r = 0, int c = 0, int r1 = 0, int r2 = 0, int r3 = 0,
          int r4 = 0) {
  if (c == n) return 0;
  if (r == 4) return solve(0, c + 1, mxs(r1), mxs(r2), mxs(r3), mxs(r4));
  int& ret = dp[r][c][r1][r2][r3][r4];
  if (ret != 0x3f3f3f3f) return ret;
  int cur_cover[] = {r1, r2, r3, r4};
  int pre_cover[] = {r1, r2, r3, r4};
  if (s[r][c] == '.' || cur_cover[r]) ret = solve(r + 1, c, r1, r2, r3, r4);
  for (int i = 1; i <= 4; ++i) {
    for (int k = r; k < min(r + i, 4); ++k) {
      cur_cover[k] = max(cur_cover[k], i);
    }
    ret = min(ret, cost[i] + solve(r + 1, c, cur_cover[0], cur_cover[1],
                                   cur_cover[2], cur_cover[3]));
    for (int k = r; k < min(r + i, 4); ++k) {
      cur_cover[k] = pre_cover[k];
    }
  }
  return ret;
}
int main() {
  cin >> n;
  for (int i = 1; i <= 4; ++i) {
    cin >> cost[i];
  }
  for (int i = 0; i < 4; ++i) {
    cin >> s[i];
  }
  memset(dp, 0x3f, sizeof dp);
  cout << solve();
}
