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 <typename T1, typename T2>
bool Max(T1& a, T2 b) {
  return a < b ? a = b, 1 : 0;
}
template <typename T1, typename T2>
bool Min(T1& a, T2 b) {
  return a > b ? a = b, 1 : 0;
}
const int N = 10000;
char a[4][N];
int f[2][1 << 12];
int add(int k, vector<int> pos) {
  for (auto& e : pos) {
    k |= 1 << e;
  }
  return k;
}
void solve() {
  int n, c1, c2, c3, c4;
  cin >> n >> c1 >> c2 >> c3 >> c4;
  for (int i = 0; i < (int)(4); ++i)
    for (int j = 0; j < (int)(n); ++j) cin >> a[i][j];
  int c = 0;
  for (int i = 0; i < (int)(1 << 12); ++i) f[0][i] = 1e9;
  f[0][0] = 0;
  for (int i = 0; i < (int)(n); ++i) {
    for (int i = 0; i < (int)(1 << 12); ++i) f[!c][i] = 1e9;
    for (int k = 0; k < (int)(1 << 12); ++k)
      if (f[c][k] < 1e9) {
        int k2 = k >> 4;
        Min(f[!c][(1 << 12) - 1], f[c][k] + c4);
        int star[4] = {0};
        for (int j = 0; j < (int)(4); ++j)
          if ((k >> j & 1) == 0 && a[j][i] == '*') star[j] = 1;
        if (star[0] + star[1] + star[2]) {
          int nk = add(k2, {0, 1, 2, 4, 5, 6});
          if (!star[3]) {
            Min(f[!c][nk], f[c][k] + c3);
          } else {
            Min(f[!c][add(nk, {3, 7})], f[c][k] + c3 + c3);
            Min(f[!c][add(nk, {3})], f[c][k] + c3 + c2);
            Min(f[!c][nk], f[c][k] + c3 + c1);
          }
        }
        if (star[1] + star[2] + star[3]) {
          int nk = add(k2, {1, 2, 3, 5, 6, 7});
          if (!star[0]) {
            Min(f[!c][nk], f[c][k] + c3);
          } else {
            Min(f[!c][add(nk, {0})], f[c][k] + c3 + c2);
            Min(f[!c][nk], f[c][k] + c3 + c1);
          }
        }
        Min(f[!c][add(k2, {0, 1, 2, 3})], f[c][k] + c2 + c2);
        Min(f[!c][add(k2, {0, 1})], f[c][k] + c2 + c1 * (star[2] + star[3]));
        Min(f[!c][add(k2, {1, 2})], f[c][k] + c2 + c1 * (star[0] + star[3]));
        Min(f[!c][add(k2, {2, 3})], f[c][k] + c2 + c1 * (star[0] + star[1]));
        Min(f[!c][k2], f[c][k] + c1 * (star[0] + star[1] + star[2] + star[3]));
      }
    c ^= 1;
  }
  int ans = 1e9;
  for (int i = 0; i < (int)(1 << 12); ++i) Min(ans, f[c][i]);
  cout << ans << '\n';
}
void init() {}
int main(void) {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.setf(ios::fixed);
  cout.precision(20);
  init();
  int TC = 1;
  for (int TI = 1; TI <= (int)(TC); ++TI) {
    solve();
  }
  return 0;
}
