#include <bits/stdc++.h>
using namespace std;
int n;
char mat[5][1004];
int dp[5][1004][1 << 12];
int a[5];
int bits[4][4];
int addcol(int mask, int y) {
  mask >>= 1;
  mask &= ~(1 << 2);
  mask &= ~(1 << 5);
  mask &= ~(1 << 8);
  mask &= ~(1 << 11);
  mask |= (mat[0][y] == '*') << 2;
  mask |= (mat[1][y] == '*') << 5;
  mask |= (mat[2][y] == '*') << 8;
  mask |= (mat[3][y] == '*') << 11;
  return mask;
}
int f(int x, int y, int mask) {
  if (x == 4) {
    x = 0;
    mask = addcol(mask, y);
    y++;
  }
  if (y == n + 3) {
    if (mask) return 1000000000;
    return 0;
  }
  if (dp[x][y][mask] != -1) return dp[x][y][mask];
  int ans = 1000000000;
  ans = min(ans, f(0, y + 1, 0) + a[4]);
  int auxmask;
  for (int i = 1; i <= 3; i++) {
    auxmask = mask & bits[i][x];
    ans = min(ans, f(x + 1, y, auxmask) + a[i]);
  }
  if (!(mask & (1 << (x * 3)))) {
    auxmask = mask;
    ans = min(ans, f(x + 1, y, auxmask));
  }
  return dp[x][y][mask] = ans;
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= 4; i++) scanf("%d", a + i);
  for (int i = 0; i < 4; i++)
    for (int j = 0; j < n; j++) scanf(" %c", &mat[i][j]);
  int mask = 0;
  for (int i = 0; i < 4; i++)
    for (int j = 0; j < 3; j++) mask |= (mat[i][j] == '*') << (i * 3 + j);
  bits[1][0] = ~1;
  bits[1][1] = ~8;
  bits[1][2] = ~64;
  bits[1][3] = ~512;
  bits[2][0] = 4068;
  bits[2][1] = 3879;
  bits[2][2] = 2367;
  bits[2][3] = 2559;
  bits[3][0] = 3584;
  bits[3][1] = 7;
  bits[3][2] = 63;
  bits[3][3] = 511;
  memset(dp, -1, sizeof dp);
  printf("%d\n", f(0, 3, mask));
  return 0;
}
