#include <bits/stdc++.h>
using namespace std;
const int N = 1e3 + 10;
const int S = 1 << 12;
char s[N];
int f[2][S + 2], a[6][N], c[10], g[10];
int n, x, cnt, mask, ans;
void up(int &a, int b) {
  if (a > b) a = b;
}
inline int get(int x) { return x ^ (S - 1); }
int main() {
  scanf("%d", &n);
  for (int i(1); i <= (4); ++i) scanf("%d", c + i);
  for (int i(1); i <= (4); ++i) {
    scanf("%s", s + 1);
    for (int j(1); j <= (n); ++j) a[i][j] = s[j] == '*';
  }
  for (int k(0); k <= (1); ++k)
    for (int i(0); i <= (S + 1); ++i) f[k][i] = 1e9;
  cnt = -1;
  mask = 0;
  for (int i(1); i <= (3); ++i) {
    for (int j(1); j <= (4); ++j) {
      ++cnt;
      if (a[j][i]) mask |= (1 << cnt);
    }
  }
  f[0][mask] = 0;
  x = 0;
  g[0] = 0;
  g[1] = 1;
  g[2] = 51;
  g[3] = 1911;
  for (int i(0); i <= (n); ++i) {
    int extra = 0;
    for (int j(1); j <= (4); ++j)
      if (a[j][i + 4]) extra |= (1 << (j + 7));
    for (int j(0); j <= (S + 1); ++j) f[x ^ 1][j] = 1e9;
    for (int j(0); j <= (S - 1); ++j) {
      if (f[x][j] >= 1e9) continue;
      for (int aa(0); aa <= (3); ++aa) {
        for (int bb(0); bb <= (3); ++bb) {
          for (int cc(0); cc <= (2); ++cc) {
            for (int dd(0); dd <= (1); ++dd) {
              int cnt = get(g[aa]) & get(g[bb] << 1) & get(g[cc] << 2) &
                        get(g[dd] << 3);
              if ((cnt & j & 15) == 0) {
                mask = (cnt & j) >> 4;
                mask ^= extra;
                up(f[x ^ 1][mask], f[x][j] + c[aa] + c[bb] + c[cc] + c[dd]);
              }
            }
          }
        }
      }
      up(f[x ^ 1][0], f[x][j] + c[4]);
    }
    x ^= 1;
  }
  printf("%d\n", f[x][0]);
  return 0;
}
