#include <bits/stdc++.h>
using namespace std;
int n, arr[5], dp[4][1005][5][5][5][5];
char s[4][1005];
int solve(int i = 0, int j = 0, int a = 0, int b = 0, int c = 0, int d = 0) {
  if (i == 4)
    return solve(0, j + 1, max(a - 1, 0), max(b - 1, 0), max(c - 1, 0),
                 max(d - 1, 0));
  if (j == n) return 0;
  int &ret = dp[i][j][a][b][c][d];
  if (~ret) return ret;
  ret = 1e9;
  int A[] = {a, b, c, d}, B[] = {a, b, c, d};
  if (A[i] || s[i][j] == '.') ret = solve(i + 1, j, a, b, c, d);
  for (int x = 1; i + x <= 4 && j + x <= n; x++) {
    for (int pos = i; pos < i + x; pos++) A[pos] = max(A[pos], x);
    ret = min(ret, solve(i + 1, j, A[0], A[1], A[2], A[3]) + arr[x]);
    for (int pos = i; pos < i + x; pos++) A[pos] = B[pos];
  }
  return ret;
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= 4; i++) scanf("%d", arr + i);
  for (int i = 0; i < 4; i++) scanf("%s", s[i]);
  memset(dp, -1, sizeof dp);
  printf("%d", solve());
  return 0;
}
