#include <bits/stdc++.h>
using namespace std;
char c;
int n, now, pos;
int w[20], f[1005];
int mx[20][20], m[20][20];
int dp[1005][(1 << 16) + 4];
void divide(int val) {
  if (val == 0) cout << '0';
  while (val) {
    cout << (val & 1);
    val >>= 1;
  }
  cout << ' ';
}
void init() {
  scanf("%d", &n);
  for (int i = 1; i <= 4; i++) scanf("%d", &w[i]);
  for (int i = 0; i < 4; i++)
    for (int j = 0; j < n; j++) {
      cin >> c;
      f[j] <<= 1;
      if (c == '*') f[j]++;
    }
  for (int i = 0; i < 4; i++)
    for (int j = 1; j <= 4 - i; j++) {
      for (int k = 0; k < 4; k++)
        for (int p = 0; p < 4; p++) m[k][p] = 1;
      for (int k = 0; k < j; k++)
        for (int p = 0; p < j; p++) m[k][i + p] = 0;
      now = 0;
      for (int k = 3; k >= 0; k--)
        for (int p = 0; p < 4; p++) now = (now << 1) + m[k][p];
      mx[i][j] = now;
    }
  memset(dp, 0x3f3f3f3f, sizeof(dp));
  for (int i = 3; i >= 0; i--) {
    pos <<= 4;
    pos += f[i];
  }
  dp[0][pos] = 0;
}
void work() {
  for (int i = 0; i <= n; i++)
    for (int j = (1 << 16) - 1; j >= 0; j--) {
      if (dp[i][j] >= 0x3f3f3f3f - 10) continue;
      if (!(j & 15)) {
        int now = (f[i + 4] << 12) | (j >> 4);
        dp[i + 1][now] = min(dp[i][j], dp[i + 1][now]);
      }
      for (int k = 0; k < 4; k++)
        for (int p = 1; p <= 4 - k; p++)
          dp[i][j & mx[k][p]] = min(dp[i][j & mx[k][p]], dp[i][j] + w[p]);
    }
}
int main() {
  init();
  work();
  printf("%d\n", dp[n][0]);
}
