#include <bits/stdc++.h>
using namespace std;
int dp[1005][1 << 12];
int a[5], mark[4];
const int MM = (1 << 12) - 1;
char mp[1005][5];
vector<int> s[4];
int cal(int index) {
  int res = 0;
  for (int i = 1; i <= 4; i++) {
    if (mp[index][i] == '*') res |= (1 << (i - 1));
  }
  return (res << 8);
}
void init() {
  for (int i = 0; i < 3; i++) {
    int val = 0;
    for (int j = 8; j >= 8 - 4 * i; j -= 4) {
      for (int k = 0; k <= i; k++) {
        val |= (1 << (j + k));
      }
    }
    mark[i] = val;
  }
  for (int k = 0; k < 4; k++) {
    for (int l = 0; l + k < 4; l++) s[l].push_back(MM ^ (mark[l] << k));
  }
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  for (int i = 1; i <= 4; i++) cin >> a[i];
  for (int i = 1; i <= 4; i++) {
    for (int j = 1; j <= n; j++) cin >> mp[j][i];
  }
  for (int i = 1; i <= n; i++) {
    for (int j = 0; j < (1 << 12); j++) dp[i][j] = 1e9;
  }
  init();
  dp[1][cal(1)] = 0;
  for (int i = 1; i <= n; i++) {
    int t = cal(i + 1);
    if (i <= 4)
      dp[i][0] = min(dp[i][0], a[4]);
    else
      dp[i][0] = min(dp[i][0], dp[i - 4][0] + a[4]);
    for (int j = MM; j >= 0; j--) {
      if (dp[i][j] == 1e9) continue;
      if ((j & 15) == 0) {
        dp[i + 1][(j >> 4) | t] = min(dp[i + 1][(j >> 4) | t], dp[i][j]);
      }
      for (int l = 0; l < 3; l++) {
        for (int k = 0; k < s[l].size(); k++) {
          int state = j & s[l][k];
          dp[i][state] = min(dp[i][state], dp[i][j] + a[l + 1]);
        }
      }
    }
  }
  cout << dp[n][0] << '\n';
  return 0;
}
