#include <bits/stdc++.h>
int dr[] = {2, 2, -2, -2, 1, -1, 1, -1};
int dc[] = {1, -1, 1, -1, 2, 2, -2, -2};
int dr1[] = {0, 0, 1, 1, 1, -1, -1, -1};
int dc1[] = {-1, 1, -1, 0, 1, -1, 0, 1};
int dr2[] = {0, 0, 1, -1};
int dc2[] = {1, -1, 0, 0};
using namespace std;
long long int dp[1004][18][18][18];
long long int a[5], n;
long long int t[6][1006];
long long int s = 0;
struct data {
  long long int r1, r2, r3, s;
};
data v[1000];
void pre(long long int c, long long int x, long long int x1, long long int x2,
         long long int s1) {
  long long int j;
  if (c == 4) {
    v[++s] = {x, x1, x2, s1};
    return;
  }
  pre(c + 1, x, x1, x2, s1);
  if (c <= 1) {
    long long int fx = x;
    long long int fx1 = x1;
    long long int fx2 = x2;
    for (j = 0; j <= 2; j++) {
      long long int p = j + c;
      fx |= (1 << p);
      fx1 |= (1 << p);
      fx2 |= (1 << p);
    }
    pre(c + 1, fx, fx1, fx2, s1 + a[3]);
  }
  if (c <= 2) {
    long long int fx = x;
    long long int fx1 = x1;
    long long int fx2 = x2;
    for (j = 0; j <= 1; j++) {
      long long int p = j + c;
      fx |= (1 << p);
      fx1 |= (1 << p);
    }
    pre(c + 1, fx, fx1, x2, s1 + a[2]);
  }
  x |= (1 << c);
  pre(c + 1, x, x1, x2, s1 + a[1]);
}
long long int cal(long long int x, long long int n1, long long int n2,
                  long long int n3) {
  long long int i, j;
  if (x == n) {
    if (n1 == 0) return 0;
    return 1e14;
  }
  long long int& r = dp[x][n1][n2][n3];
  if (r != -1) return r;
  r = 1e14;
  r = min(r, a[4] + cal(x + 1, 15, 15, 15));
  for (i = 1; i <= s; i++) {
    long long int x1 = (v[i].r1 | n1);
    long long int x2 = v[i].r2;
    long long int x3 = v[i].r3;
    long long int c = v[i].s;
    bool f = 0;
    for (j = 0; j < 4; j++) {
      long long int p = x1 & (1 << j);
      if (p == 0 && t[j][x] == 1) {
        f = 1;
        break;
      }
    }
    if (f == 1) continue;
    long long int k = cal(x + 1, (n2 | x2), (x3 | n3), 0) + c;
    r = min(r, k);
  }
  return r;
}
int main() {
  long long int i, j;
  while (cin >> n) {
    for (long long int i = 1; i < 5; i++) cin >> a[i];
    for (i = 0; i < 4; i++) {
      for (j = 0; j < n; j++) {
        char ch;
        cin >> ch;
        if (ch == '*')
          t[i][j] = 1;
        else
          t[i][j] = 0;
      }
    }
    memset(dp, -1, sizeof(dp));
    pre(0, 0, 0, 0, 0);
    long long int ans = cal(0, 0, 0, 0);
    cout << ans << endl;
  }
  return 0;
}
