You are given a matrix f with 4 rows and n columns. Each element of the matrix is either an asterisk (*) or a dot (.).

You may perform the following operation arbitrary number of times: choose a square submatrix of f with size k × k (where 1 ≤ k ≤ 4) and replace each element of the chosen submatrix with a dot. Choosing a submatrix of size k × k costs ak coins.

What is the minimum number of coins you have to pay to replace all asterisks with dots?

Input

The first line contains one integer n (4 ≤ n ≤ 1000) — the number of columns in f.

The second line contains 4 integers a1, a2, a3, a4 (1 ≤ ai ≤ 1000) — the cost to replace the square submatrix of size 1 × 1, 2 × 2, 3 × 3 or 4 × 4, respectively.

Then four lines follow, each containing n characters and denoting a row of matrix f. Each character is either a dot or an asterisk.

Output

Print one integer — the minimum number of coins to replace all asterisks with dots.

Examples

Input

4
1 10 8 20
***.
***.
***.
...*


Output

9


Input

7
2 1 8 2
.***...
.***..*
.***...
....*..


Output

3


Input

4
10 10 1 10
***.
*..*
*..*
.***


Output

2

Note

In the first example you can spend 8 coins to replace the submatrix 3 × 3 in the top-left corner, and 1 coin to replace the 1 × 1 submatrix in the bottom-right corner.

In the second example the best option is to replace the 4 × 4 submatrix containing columns 2 – 5, and the 2 × 2 submatrix consisting of rows 2 – 3 and columns 6 – 7.

In the third example you can select submatrix 3 × 3 in the top-left corner and then submatrix 3 × 3 consisting of rows 2 – 4 and columns 2 – 4.
#include <bits/stdc++.h>
using namespace std;
template <class T>
inline void read(T& x) {
  char c;
  bool f = 0;
  while ((c = getchar()) < '0' || '9' < c) f |= (c == '-');
  for (x = (c ^ 48); '0' <= (c = getchar()) && c <= '9';
       x = (x << 1) + (x << 3) + (c ^ 48))
    ;
  if (f) x = -x;
}
template <class T>
inline T read(const T sample) {
  T x = 0;
  char c;
  bool f = 0;
  while ((c = getchar()) < '0' || '9' < c) f |= (c == '-');
  for (x = (c ^ 48); '0' <= (c = getchar()) && c <= '9';
       x = (x << 1) + (x << 3) + (c ^ 48))
    ;
  return f ? -x : x;
}
template <class T>
void fwrit(const T x) {
  if (x < 0) return (void)(putchar('-'), fwrit(-x));
  if (x > 9) fwrit(x / 10);
  putchar(x % 10 ^ 48);
}
template <class T>
inline T Max(const T x, const T y) {
  return x > y ? x : y;
}
template <class T>
inline T Min(const T x, const T y) {
  return x < y ? x : y;
}
template <class T>
inline T fab(const T x) {
  return x > 0 ? x : -x;
}
inline int gcd(const int a, const int b) { return b ? gcd(b, a % b) : a; }
inline void getInv(int inv[], const int lim, const int MOD) {
  inv[0] = inv[1] = 1;
  for (int i = 2; i <= lim; ++i)
    inv[i] = 1ll * inv[MOD % i] * (MOD - MOD / i) % MOD;
}
inline long long mulMod(const long long a, const long long b,
                        const long long mod) {
  return ((a * b - (long long)((long double)a / mod * b + 1e-8) * mod) % mod +
          mod) %
         mod;
}
const int maxn = 1000;
const int maxsize = 1 << 12;
const int all = maxsize - 1;
const int inf = 0x3f3f3f3f;
int a[5], n;
char mat[5][maxn + 5];
int st[maxn + 5];
vector<int> v[4];
int f[maxn + 5][maxsize + 5];
inline void Init() {
  n = read(1);
  for (signed i = (0), i_end_ = (3); i <= i_end_; ++i) a[i] = read(1);
  for (signed i = (0), i_end_ = (3); i <= i_end_; ++i) scanf("%s", mat[i]);
  for (signed i = (0), i_end_ = (n - 1); i <= i_end_; ++i)
    for (signed j = (0), j_end_ = (3); j <= j_end_; ++j)
      st[i] = st[i] << 1 | (mat[j][i] == '*');
  for (signed i = (0), i_end_ = (2); i <= i_end_; ++i)
    for (signed j = (0), j_end_ = (3); j <= j_end_; ++j)
      for (int l = 0; i + l <= 2 && j + l <= 3; ++l) {
        int tmp = all;
        for (signed x = (i), x_end_ = (i + l); x <= x_end_; ++x)
          for (signed y = (j), y_end_ = (j + l); y <= y_end_; ++y)
            tmp ^= 1 << x * 4 + y;
        v[l].push_back(tmp);
      }
}
inline void getMin(int& x, const int y) {
  if (y < x) x = y;
}
inline void Get_f() {
  memset(f, 0x3f, sizeof f);
  f[2][st[0] << 8 | st[1] << 4 | st[2]] = 0;
  for (signed i = (2), i_end_ = (n - 1); i <= i_end_; ++i)
    for (signed s = (all), s_end_ = (0); s >= s_end_; --s)
      if (f[i][s] != inf) {
        if (s < (1 << 8)) getMin(f[i + 1][s << 4 | st[i + 1]], f[i][s]);
        getMin(f[i + 1][0], f[i][s] + a[3]);
        for (signed l = (0), l_end_ = (2); l <= l_end_; ++l)
          for (int opt : v[l]) getMin(f[i][s & opt], f[i][s] + a[l]);
      }
  fwrit(f[n - 1][0]), putchar('\n');
}
signed main() {
  Init();
  Get_f();
  return 0;
}
