#include <bits/stdc++.h>
using namespace std;
const int maxn = 1001, maxk = 16;
int N, cost[4], dp[maxn][1 << maxk], mm[4][4];
char arr[maxk][maxn], tmp[4][4];
inline int gm(int col) {
  if (col >= N) return 15;
  int msk = 0;
  for (int i = 0; i < 4; i++)
    if (arr[i][col] == '.') msk ^= (1 << i);
  return msk;
}
inline int gm(int col, char t[4][4]) {
  int msk = 0;
  for (int i = 0; i < 4; i++)
    if (t[i][col] == '.') msk ^= (1 << i);
  return msk;
}
inline int combine(int a, int b, int c, int d) {
  return a | (b << 4) | (c << 8) | (d << 12);
}
int solve(int col, int msk) {
  if (col == N) {
    if (msk == 65535) return 0;
    return 0x3f3f3f3f;
  }
  if (dp[col][msk] != -1) return dp[col][msk];
  vector<int> v;
  for (int i = 0; i < 4; i++) {
    int t = msk >> (i * 4);
    v.push_back(t & ((1 << 4) - 1));
  }
  if (v[0] == 15) {
    int tot = combine(v[1], v[2], v[3], gm(col + 4));
    return dp[col][msk] = solve(col + 1, tot);
  }
  int res = 0x3f3f3f3f;
  for (int i = 0; i < 4; i++) {
    for (int sz = 0; sz < 4; sz++) {
      int nm = msk | mm[i][sz];
      if (nm == msk) continue;
      res = min(res, solve(col, nm) + cost[sz]);
    }
  }
  return dp[col][msk] = res;
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cin >> N;
  for (int i = 0; i < 4; i++) cin >> cost[i];
  for (int i = 0; i < 4; i++)
    for (int k = 0; k < N; k++) cin >> arr[i][k];
  for (int i = 0; i < 4; i++) {
    for (int k = 1; k <= 4; k++) {
      for (int a = 0; a < 4; a++)
        for (int b = 0; b < 4; b++) tmp[a][b] = '*';
      for (int r = i; r < i + k; r++)
        for (int c = 0; c < k; c++) tmp[r][c] = '.';
      mm[i][k - 1] = combine(gm(0, tmp), gm(1, tmp), gm(2, tmp), gm(3, tmp));
    }
  }
  memset(dp, -1, sizeof dp);
  int m = combine(gm(0), gm(1), gm(2), gm(3));
  cout << solve(0, m) << '\n';
}
