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 int maxn = 1e3 + 7;
const int mst = (1 << 16);
char str[4][maxn];
int col[maxn], rec[4][4], dp[maxn][mst], a[5];
inline void outb(long long x) {
  long long bin[64], sz = 0;
  memset(bin, 0, sizeof(bin));
  for (long long i = 1; i <= x; i <<= 1LL)
    if (x & i)
      bin[sz++] = 1;
    else
      bin[sz++] = 0;
  reverse(bin, bin + 16);
  for (int i = 0; i < 16; ++i) printf("%I64d", bin[i]);
  puts("");
}
void init() {
  memset(col, 0, sizeof(col));
  memset(dp, -1, sizeof(dp));
  for (int i = 0; i < 4; ++i) {
    for (int j = 0; j < 4; ++j) {
      int ret = 0;
      for (int k = 0; k <= j; ++k) ret = (ret << 1) | 1;
      ret <<= (3 - j);
      for (int k = 0; k <= j; ++k) rec[i][j] = ((rec[i][j] << 4) | (ret >> i));
      rec[i][j] <<= (3 - j) * 4;
      rec[i][j] ^= (mst - 1);
    }
  }
}
int main() {
  int n, ret = 0;
  init();
  scanf("%d", &n);
  for (int i = 0; i < 4; ++i) scanf("%d", &a[i]);
  for (int i = 0; i < 4; ++i) scanf("%s", str[i]);
  for (int i = 0; i < n; ++i)
    for (int j = 0; j < 4; ++j)
      col[i] = ((col[i] << 1) | (str[j][i] == '*' ? 1 : 0));
  for (int i = 0; i < 4; ++i) ret = ((ret << 4) | col[i]);
  dp[0][ret] = 0;
  for (int i = 0; i < n; ++i) {
    for (int st = mst - 1; st >= 0; --st) {
      if (dp[i][st] == -1) continue;
      if (!((st >> 12) & 15)) {
        int S = (col[i + 4] | ((st & ((1 << 12) - 1)) << 4));
        if (dp[i + 1][S] == -1)
          dp[i + 1][S] = dp[i][st];
        else
          dp[i + 1][S] = min(dp[i + 1][S], dp[i][st]);
      }
      for (int j = 0; j < 4; ++j)
        for (int k = 0; k < 4; ++k) {
          if (dp[i][st & rec[k][j]] == -1)
            dp[i][st & rec[k][j]] = dp[i][st] + a[j];
          else
            dp[i][st & rec[k][j]] =
                min(dp[i][st & rec[k][j]], dp[i][st] + a[j]);
        }
    }
  }
  printf("%d\n", dp[n][0]);
  return 0;
}
