#include <bits/stdc++.h>
using namespace std;
char ch[5][1005];
const int inf = 0x3f3f3f3f;
int a[1005], cost[5], dp[1001][5000];
int change[5][5];
int len[5] = {0, 4, 3, 2};
int main() {
  int n, i, j;
  for (i = 0; i < 4; i++) change[1][i] = 1 << (i + 8);
  for (i = 0; i < 3; i++) {
    int temp =
        (1 << (i + 4)) + (1 << (i + 5)) + (1 << (i + 8)) + (1 << (i + 9));
    change[2][i] = temp;
  }
  for (i = 0; i < 2; i++) {
    int temp = (1 << (i + 4)) + (1 << (i + 5)) + (1 << (i + 6)) +
               (1 << (i + 8)) + (1 << (i + 9)) + (1 << (i + 10)) + (1 << i) +
               (1 << (i + 1)) + (1 << (i + 2));
    change[3][i] = temp;
  }
  memset(dp, inf, sizeof(dp));
  cin >> n;
  for (i = 1; i <= 4; i++) cin >> cost[i];
  for (i = 1; i <= 4; i++) cin >> ch[i] + 1;
  for (i = 1; i <= n; i++) {
    int temp = 0;
    for (j = 1; j <= 4; j++) {
      if (ch[j][i] == '.') temp += (1 << (j - 1));
    }
    a[i] = temp;
  }
  int temp = 0;
  for (i = 1; i <= 3; i++) {
    temp >>= 4;
    temp += a[i] << 8;
    dp[i][temp] = 0;
  }
  for (i = 1; i <= n; i++) {
    for (j = 0; j < 4096; j++) {
      if (((j & 15) == 15) || i <= 3) {
        int now = (j >> 4) + (a[i] << 8);
        dp[i][now] = min(dp[i][now], dp[i - 1][j]);
      }
      dp[i][4095] = min(dp[i][4095], dp[i - 1][j] + cost[4]);
    }
    for (int state = 0; state < 4096; state++) {
      for (j = 1; j < 4; j++) {
        for (int k = 0; k < len[j]; k++) {
          int now = state | change[j][k];
          dp[i][now] = min(dp[i][now], dp[i][state] + cost[j]);
        }
      }
      dp[i][4095] = min(dp[i][4095], dp[i][state] + cost[4]);
    }
  }
  cout << dp[n][4095] << endl;
  return 0;
}
