#include <bits/stdc++.h>
using namespace std;
const int N = 1e3 + 15;
const int B = 16;
const int BIT = (1 << B);
char s[4][N];
int a[4];
int dp[2][BIT];
const int G = (1 << 12) - 1;
int cost[10], cbit[10];
int mp[4][4];
void solve2(int test = 1) {
  int n;
  scanf("%d", &n);
  for (int i = 0; i < 4; ++i) scanf("%d ", &a[i]);
  int parity = 0;
  const int inf = 2e9;
  for (int i = 0; i < BIT; ++i) dp[parity][i] = inf;
  dp[parity][0] = 0;
  for (int i = 0; i < 4; ++i) {
    scanf(" %s ", s[i]);
  }
  int num_op = 0;
  for (int i = 0; i < 4; ++i) {
    for (int k = 1; i + k - 1 < 4; ++k) {
      memset(mp, 0, sizeof(mp));
      for (int x = 0; x < k; ++x) {
        for (int y = 0; y < k; ++y) {
          mp[x + i][y] = 1;
        }
      }
      int bit = 0, t = 0;
      for (int col = 3; col >= 0; --col) {
        for (int row = 0; row < 4; ++row) {
          if (mp[row][col]) bit |= (1 << t);
          ++t;
        }
      }
      cbit[num_op] = bit, cost[num_op] = a[k - 1];
      ++num_op;
    }
  }
  for (int i = 0; i < n; ++i) {
    int need_bit = 0;
    if (i - 3 >= 0) {
      for (int j = 0; j < 4; ++j) {
        if (s[j][i - 3] == '*') need_bit |= (1 << j);
      }
    }
    int next_parity = parity ^ 1;
    for (int j = 0; j < BIT; ++j) dp[next_parity][j] = inf;
    for (int j = 0; j < BIT; ++j) {
      if (dp[parity][j] == inf) continue;
      dp[parity][BIT - 1] = min(dp[parity][BIT - 1], dp[parity][j] + a[3]);
      if ((need_bit & j) != need_bit) continue;
      dp[next_parity][j >> 4] = min(dp[next_parity][j >> 4], dp[parity][j]);
      for (int k = 0; k < num_op; ++k) {
        dp[parity][j | cbit[k]] =
            min(dp[parity][j | cbit[k]], dp[parity][j] + cost[k]);
      }
    }
    parity = next_parity;
  }
  int ret = inf;
  int bit = 0, t = 0;
  for (int col = n - 4; col < n; ++col) {
    for (int row = 0; row < 4; ++row) {
      if (s[row][col] == '*') bit |= (1 << t);
      ++t;
    }
  }
  for (int i = 0; i < BIT; ++i) {
    if ((i & bit) != bit) continue;
    ret = min(ret, dp[parity ^ 1][i]);
  }
  printf("%d\n", ret);
}
void solve() { solve2(); }
int main(void) {
  solve();
  return 0;
}
