#include <bits/stdc++.h>
using namespace std;
int n, cost[5], rowMask[1000 + 20];
long long minCost[1000 + 1][1 << 12];
char f[1000][4];
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cin >> n;
  cin >> cost[1] >> cost[2] >> cost[3] >> cost[4];
  for (int i = 0; i < (4); i++)
    for (int j = 0; j < (n); j++) cin >> f[j][i];
  for (int i = 0; i < (n); i++)
    for (int j = 0; j < (4); j++)
      if (f[i][j] == '*') rowMask[i] |= (1 << j);
  for (int i = 0; i < (n + 1); i++)
    for (int mask = (1 << 12) - 1; mask >= 0; mask--)
      minCost[i][mask] = INT_MAX;
  minCost[0][(rowMask[0] << 8) | (rowMask[1] << 4) | rowMask[2]] = 0;
  for (int i = 0; i < (n); i++)
    for (int mask = (1 << 12) - 1; mask >= 0; mask--) {
      if (minCost[i][mask] == INT_MAX) continue;
      if (mask < (1 << 8)) {
        minCost[i + 1][(mask << 4) | rowMask[i + 3]] =
            min(minCost[i + 1][(mask << 4) | rowMask[i + 3]], minCost[i][mask]);
        continue;
      }
      minCost[min(n, i + 4)][(rowMask[i + 4] << 8) | (rowMask[i + 5] << 4) |
                             rowMask[i + 6]] =
          min(minCost[min(n, i + 4)][(rowMask[i + 4] << 8) |
                                     (rowMask[i + 5] << 4) | rowMask[i + 6]],
              minCost[i][mask] + cost[4]);
      minCost[i][mask & 0b000100010001] =
          min(minCost[i][mask & 0b000100010001], minCost[i][mask] + cost[3]);
      minCost[i][mask & 0b100010001000] =
          min(minCost[i][mask & 0b100010001000], minCost[i][mask] + cost[3]);
      minCost[i][mask & 0b110011001111] =
          min(minCost[i][mask & 0b110011001111], minCost[i][mask] + cost[2]);
      minCost[i][mask & 0b100110011111] =
          min(minCost[i][mask & 0b100110011111], minCost[i][mask] + cost[2]);
      minCost[i][mask & 0b001100111111] =
          min(minCost[i][mask & 0b001100111111], minCost[i][mask] + cost[2]);
      minCost[i][mask & 0b011111111111] =
          min(minCost[i][mask & 0b011111111111], minCost[i][mask] + cost[1]);
      minCost[i][mask & 0b101111111111] =
          min(minCost[i][mask & 0b101111111111], minCost[i][mask] + cost[1]);
      minCost[i][mask & 0b110111111111] =
          min(minCost[i][mask & 0b110111111111], minCost[i][mask] + cost[1]);
      minCost[i][mask & 0b111011111111] =
          min(minCost[i][mask & 0b111011111111], minCost[i][mask] + cost[1]);
    }
  cout << minCost[n][0];
  return 0;
}
