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;
const long long BIG = 1000000000000000000LL;
void solve();
signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  solve();
  return 0;
}
const long long borne = 1010;
long long nbCol;
long long prix[4];
bool doitTuer[borne][4];
long long dp[borne][16][16][16];
long long base[borne];
long long calc(long long col, long long m0, long long m1, long long m2) {
  long long &rep = dp[col][m0][m1][m2];
  if (rep != -1) return rep;
  rep = BIG;
  rep = calc(col + 4, base[col + 4], base[col + 5], base[col + 6]) + prix[3];
  if (m0 == 15) rep = min(rep, (dp[col + 1][m1][m2][base[col + 3]]));
  rep = min(rep, (calc(col, m0 | 1, m1, m2) + prix[0]));
  rep = min(rep, (calc(col, m0 | 3, m1 | 3, m2) + prix[1]));
  rep = min(rep, (calc(col, m0 | 7, m1 | 7, m2 | 7) + prix[2]));
  rep = min(rep, (calc(col, m0 | 2, m1, m2) + prix[0]));
  rep = min(rep, (calc(col, m0 | 6, m1 | 6, m2) + prix[1]));
  rep = min(rep, (calc(col, m0 | 14, m1 | 14, m2 | 14) + prix[2]));
  rep = min(rep, (calc(col, m0 | 4, m1, m2) + prix[0]));
  rep = min(rep, (calc(col, m0 | 12, m1 | 12, m2) + prix[1]));
  rep = min(rep, (calc(col, m0 | 8, m1, m2) + prix[0]));
  return rep;
}
void solve() {
  cin >> nbCol;
  for (long long i = (0); i < (4); ++i) cin >> prix[i];
  for (long long iLig = (0); iLig < (4); ++iLig) {
    for (long long iCol = (0); iCol < (nbCol); ++iCol) {
      char c;
      cin >> c;
      if (c == '*') doitTuer[iCol][iLig] = true;
    }
  }
  for (long long iCol = (0); iCol < (nbCol + 8); ++iCol) {
    for (long long iLig = (0); iLig < (4); ++iLig)
      if (!doitTuer[iCol][iLig]) base[iCol] |= (1LL << iLig);
  }
  for (long long iCol = (0); iCol < (nbCol); ++iCol)
    for (long long m0 = (0); m0 < (16); ++m0)
      for (long long m1 = (0); m1 < (16); ++m1)
        for (long long m2 = (0); m2 < (16); ++m2) dp[iCol][m0][m1][m2] = -1;
  for (long long iCol = (nbCol - 1); iCol >= (0); --iCol)
    for (long long m0 = (0); m0 < (16); ++m0)
      for (long long m1 = (0); m1 < (16); ++m1)
        for (long long m2 = (0); m2 < (16); ++m2) calc(iCol, m0, m1, m2);
  cout << calc(0, base[0], base[1], base[2]) << "\n";
}
