#include <bits/stdc++.h>
using namespace std;
const int maxn = 1005;
int n, m, w[4], a[4][maxn], st[maxn], dp[maxn][(1 << 13)];
char mp[4][maxn];
int ss[4][3] = {{8, 4, 0}, {9, 5, 1}, {10, 6, 2}, {11, 7, 3}};
vector<int> c[4];
int main() {
  cin >> n >> w[0] >> w[1] >> w[2] >> w[3];
  for (int i = 0; i < 4; i++)
    for (int j = 0; j < n; j++) {
      cin >> mp[i][j];
      if (mp[i][j] == '*')
        a[i][j] = 1;
      else
        a[i][j] = 0;
    }
  for (int j = 0; j < n; j++)
    for (int i = 0; i < 4; i++) {
      st[j] |= (a[i][j] << i);
    }
  for (int l = 1; l <= 3; l++)
    for (int i = 0; i + l - 1 < 4; i++)
      for (int j = 0; j + l - 1 < 3; j++) {
        int tmp = 0;
        for (int x = i; x - i + 1 <= l; x++)
          for (int y = j; y - j + 1 <= l; y++) tmp |= (1 << ss[x][y]);
        c[l - 1].push_back(tmp);
      }
  memset(dp, 0x3f3f3f3f, sizeof(dp));
  dp[0][st[0]] = 0;
  dp[1][(st[0] << 4) | st[1]] = 0;
  dp[2][(st[0] << 8) | (st[1] << 4) | st[2]] = 0;
  for (int i = 2; i < n; i++)
    for (int sta = (1 << 12); sta >= 0; sta--)
      if (dp[i][sta] != 0x3f3f3f3f) {
        if (sta < (1 << 8))
          dp[i + 1][(sta << 4) | st[i + 1]] =
              min(dp[i + 1][(sta << 4) | st[i + 1]], dp[i][sta]);
        dp[i + 1][0] = min(dp[i + 1][0], dp[i][sta] + w[3]);
        for (int t = 0; t < 3; t++) {
          for (int k = 0; k < c[t].size(); k++) {
            int now = c[t][k];
            now ^= ((1 << 12) - 1);
            dp[i][sta & now] = min(dp[i][sta & now], dp[i][sta] + w[t]);
          }
        }
      }
  cout << dp[n - 1][0] << endl;
}
