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;
constexpr long long MOD = 1e9 + 7;
const long long INF = 1e10;
int n;
int b[1010], a[10];
long long dp[1010][1 << 12];
int clear(int s, int row, int k) {
  for (int i = 0; i < k; ++i) {
    for (int j = row; j < row + k; ++j) {
      s &= ~(1 << (4 * i + j));
    }
  }
  return s;
}
void solve() {
  for (int s = 0; s < (1 << 12); ++s) dp[0][s] = INF;
  dp[0][0] = 0;
  for (int k = 1; k <= 3; ++k) {
    for (int s = 0; s < (1 << (4 * k)); ++s) {
      int S = s << (4 * (3 - k));
      for (int row = 0; row < 4; ++row) {
        for (int sz = 1; sz <= k; ++sz) {
          if (row + sz - 1 >= 4) break;
          dp[0][S] =
              min(dp[0][S], dp[0][clear(s, row, sz) << (4 * (3 - k))] + a[sz]);
        }
      }
    }
  }
  for (int i = 1; i <= n - 3; ++i) {
    for (int s = 0; s < (1 << 12); ++s) {
      dp[i][s] = dp[i - 1][0] + a[4];
      if (!(s & ((1 << 4) - 1))) {
        dp[i][s] = min(dp[i][s], dp[i - 1][(s >> 4) | (b[i] << 8)]);
      }
      for (int row = 0; row < 4; ++row) {
        for (int k = 1; k <= 3; ++k) {
          if (row + k - 1 >= 4) break;
          dp[i][s] = min(dp[i][s], dp[i][clear(s, row, k)] + a[k]);
        }
      }
    }
  }
  cout << dp[n - 3][(b[n - 2] << 8) | (b[n - 1] << 4) | b[n]] << endl;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin >> n;
  for (int i = 1; i <= 4; ++i) cin >> a[i];
  string s[4];
  for (int i = 0; i < 4; ++i) cin >> s[i];
  for (int j = 0; j < n; ++j) {
    for (int i = 0; i < 4; ++i) {
      if (s[i][j] == '*') {
        b[j + 1] ^= (1 << i);
      }
    }
  }
  solve();
  return 0;
}
