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;
int inf = (1e9) + 7;
int mod = 998244353;
int c1;
int c2;
int c3;
int c4;
int m[5][1005];
int n;
int tb[1001][1 << 12];
int go(int col, int mask, int old_mask) {
  if (col == n) {
    return 0;
  }
  if (tb[col][mask] != -1) return tb[col][mask];
  int n1 = (!(m[0][col])) and (!(mask & (1 << 0)));
  int n2 = (!(m[1][col])) and (!(mask & (1 << 1)));
  int n3 = (!(m[2][col])) and (!(mask & (1 << 2)));
  int n4 = (!(m[3][col])) and (!(mask & (1 << 3)));
  int aux = inf;
  int nmask = (mask >> 4);
  if (col < n - 3) aux = min(aux, c4 + go(col + 1, (1 << 12) - 1, mask));
  if (!n1 and !n2 and !n3 and !n4) {
    aux = min(aux, go(col + 1, nmask, mask));
    tb[col][mask] = aux;
  }
  int v1 = 1;
  int v2 = v1;
  v2 += 1 << 4;
  v2 += 1 << 1;
  v2 += 1 << 5;
  int v3 = v2;
  v3 += 1 << 8;
  v3 += 1 << 9;
  v3 += 1 << 10;
  v3 += 1 << 6;
  v3 += 1 << 2;
  if ((mask | v1) != old_mask) aux = min(aux, c1 + go(col, mask | v1, mask));
  if (col < n - 1 and (mask | v2) != old_mask)
    aux = min(aux, c2 + go(col, mask | v2, mask));
  if (col < n - 2 and (mask | v3) != old_mask)
    aux = min(aux, c3 + go(col, mask | v3, mask));
  v1 <<= 1;
  v2 <<= 1;
  v3 <<= 1;
  if ((mask | v1) != old_mask) aux = min(aux, c1 + go(col, mask | v1, mask));
  if (col < n - 1 and (mask | v2) != old_mask)
    aux = min(aux, c2 + go(col, mask | v2, mask));
  if (col < n - 2 and (mask | v3) != old_mask)
    aux = min(aux, c3 + go(col, mask | v3, mask));
  v1 <<= 1;
  v2 <<= 1;
  if ((mask | v1) != old_mask) aux = min(aux, c1 + go(col, mask | v1, mask));
  if (col < n - 1 and (mask | v2) != old_mask)
    aux = min(aux, c2 + go(col, mask | v2, mask));
  v1 <<= 1;
  if ((mask | v1) != old_mask) aux = min(aux, c1 + go(col, mask | v1, mask));
  tb[col][mask] = aux;
  return aux;
}
int main() {
  memset(tb, -1, sizeof(tb));
  scanf("%d", &n);
  scanf("%d %d %d", &c1, &c2, &c3);
  scanf("%d", &c4);
  for (int i = 0; i < 4; ++i) {
    string s;
    cin >> s;
    for (int j = 0; j < s.size(); ++j) {
      m[i][j] = (s[j] == '.');
    }
  }
  long long ans = go(0, 0, 1 << 13);
  printf("%lld\n", ans);
}
