#include <bits/stdc++.h>
using namespace std;
int n, a[5];
string s[5];
long long int dp[1005][5][5005];
long long int solve(int st, int ini, int mask) {
  if (dp[st][ini][mask] != -1) return dp[st][ini][mask];
  if (st == n + 1) return dp[st][ini][mask] = 0;
  long long int& ret = dp[st][ini][mask];
  int app = min(4, n - st + 1);
  int tem[17], pre[17];
  for (int i = 1; i <= 12; ++i) {
    if (mask & (1LL << (i - 1)))
      tem[i] = 1;
    else
      tem[i] = 0;
  }
  if (st + 3 > n)
    for (int i = 13; i <= 16; ++i) tem[i] = 0;
  else
    for (int i = 13; i <= 16; ++i) {
      if (s[i - 12][st + 3] == '*')
        tem[i] = 1;
      else
        tem[i] = 0;
    }
  for (int i = 1; i <= 16; ++i) pre[i] = tem[i];
  ret = 1e17;
  for (int x = ini; x <= 4; ++x)
    for (int sz = 0; sz <= min(app, 5 - x); ++sz) {
      for (int i = 1; i <= 16; ++i) tem[i] = pre[i];
      for (int ps = x; ps <= x + sz - 1; ++ps)
        for (int rt = 0; rt <= sz - 1; ++rt) {
          tem[ps + rt * 4] = 0;
        }
      if (tem[1] || tem[2] || tem[3] || tem[4]) {
        int nmask = 0;
        for (int i = 1; i <= 12; ++i)
          if (tem[i]) nmask += (1 << (i - 1));
        if (nmask != mask) ret = min(ret, a[sz] + solve(st, ini, nmask));
      } else {
        int nmask = 0;
        for (int i = 5; i <= 16; ++i)
          if (tem[i]) nmask += (1 << (i - 5));
        ret = min(ret, a[sz] + solve(st + 1, 1, nmask));
        nmask = 0;
        for (int i = 1; i <= 12; ++i)
          if (tem[i]) nmask += (1 << (i - 1));
        if (ini != 4) ret = min(ret, a[sz] + solve(st, ini + 1, nmask));
      }
    }
  return ret;
}
int main() {
  cin >> n;
  for (int i = 1; i <= 4; ++i) cin >> a[i];
  for (int i = 1; i <= 4; ++i) {
    cin >> s[i];
    s[i] = "$" + s[i];
  }
  for (int i = 1; i <= n + 1; ++i)
    for (int kk = 1; kk <= 4; ++kk)
      for (int j = 0; j <= 5000; ++j) dp[i][kk][j] = -1;
  int cmask = 0;
  for (int j = 1; j <= 3; ++j)
    for (int i = 1; i <= 4; ++i) {
      int ps = (j - 1) * 4 + i;
      if (s[i][j] == '*') cmask += (1LL << (ps - 1));
    }
  cout << solve(1, 1, cmask) << '\n';
}
