#include <bits/stdc++.h>
using namespace std;
const int N = 1005, inf = 0x3f3f3f3f, B = ((1 << 16) - 1);
int n, c[5], f[2][B + 5], zz[N];
char mp[5][N];
vector<int> ve[5];
int main() {
  int i, j, k, l, t, z, lz, up, tmp, o, S;
  scanf("%d", &n);
  for (i = 1; i <= 4; i++) scanf("%d", &c[i]);
  for (i = 0; i < 4; i++) scanf("%s", mp[i]);
  for (i = 0; i < n; i++) {
    for (j = 0; j < 4; j++) zz[i] = (zz[i] << 1) + (mp[j][i] != '.') ? 1 : 0;
  }
  for (i = 1; i <= 4; i++) {
    for (j = 0; j + i <= 4; j++) {
      o = B;
      for (k = j; k < j + i; k++)
        for (l = 0; l < i; l++) o ^= (1 << (l * 4 + k));
      ve[i].push_back(o);
    }
  }
  for (i = 0; i < 2; i++)
    for (j = B; ~j; j--) f[i][j] = inf;
  for (i = 0; i < 4; i++)
    for (j = 0; j < 4; j++)
      if (mp[i][j] == '*') S |= (1 << (j * 4 + i));
  f[0][S] = 0;
  for (i = 0; i < n; i++) {
    t = i & 1;
    for (lz = B; ~lz; lz--)
      if (f[t][lz] != inf) {
        if (!(lz & 15)) {
          z = (lz >> 4);
          for (j = 0; j < 4; j++)
            if (mp[j][i + 4] == '*') z |= (1 << (12 + j));
          f[t ^ 1][z] = f[t][lz];
        }
        for (j = 1; j <= 4; j++) {
          for (vector<int>::iterator it = ve[j].begin(); it != ve[j].end();
               it++)
            f[t][lz & (*it)] = min(f[t][lz & (*it)], f[t][lz] + c[j]);
        }
      }
    memset(f[t], inf, sizeof f[t]);
  }
  printf("%d\n", f[n & 1][0]);
}
