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 n;
int a[5];
string s[1005];
string t[1005];
int memo[1005][5][5][5][5][5];
int solve2(int i, int j, int x1, int x2, int x3, int x4, int k);
int solve(int i, int j, int x1, int x2, int x3, int x4) {
  if (i == n) {
    return 0;
  }
  int &ret = memo[i][j][x1][x2][x3][x4];
  if (ret != -1) return ret;
  ret = 1e9;
  for (int k = 0; k <= 4; k++) {
    ret = min(ret, solve2(i, j, x1, x2, x3, x4, k));
  }
  return ret;
}
int solve2(int i, int j, int x1, int x2, int x3, int x4, int k) {
  if (k == 0) {
    if (s[i][j] == '*') {
      bool ok1 = (j == 0 && x1 == 0);
      bool ok2 = (j == 1 && x2 == 0);
      bool ok3 = (j == 2 && x3 == 0);
      bool ok4 = (j == 3 && x4 == 0);
      if (ok1 | ok2 | ok3 | ok4) return 1e9;
    }
    if (j == 3) {
      return solve(i + 1, 0, max(0, x1 - 1), max(0, x2 - 1), max(0, x3 - 1),
                   max(0, x4 - 1));
    }
    return solve(i, j + 1, x1, x2, x3, x4);
  }
  int y1, y2, y3, y4;
  if (j == 0) {
    y1 = x1;
    y2 = x2;
    y3 = x3;
    y4 = x4;
    y1 = max(y1, k);
    if (k > 1) {
      y2 = max(y2, k);
    }
    if (k > 2) {
      y3 = max(y3, k);
    }
    if (k > 3) {
      y4 = max(y4, k);
    }
    return a[k - 1] + solve(i, j + 1, y1, y2, y3, y4);
  } else if (j == 1) {
    y1 = x1;
    y2 = x2;
    y3 = x3;
    y4 = x4;
    y2 = max(y2, k);
    if (k > 1) {
      y3 = max(y3, k);
    }
    if (k > 2) {
      y4 = max(y4, k);
    }
    return a[k - 1] + solve(i, j + 1, y1, y2, y3, y4);
  } else if (j == 2) {
    y1 = x1;
    y2 = x2;
    y3 = x3;
    y4 = x4;
    y3 = max(y3, k);
    if (k > 1) {
      y4 = max(y4, k);
    }
    return a[k - 1] + solve(i, j + 1, y1, y2, y3, y4);
  } else {
    y1 = max(0, x1 - 1);
    y2 = max(0, x2 - 1);
    y3 = max(0, x3 - 1);
    y4 = max(0, x4 - 1);
    y4 = max(y4, k - 1);
    return a[k - 1] + solve(i + 1, 0, y1, y2, y3, y4);
  }
}
int main() {
  memset(memo, -1, sizeof(memo));
  cin >> n;
  for (int i = 0; i < 4; i++) cin >> a[i];
  for (int i = 0; i < 4; i++) cin >> t[i];
  for (int i = 0; i < n; i++) {
    s[i] = "";
    for (int j = 0; j < 4; j++) {
      s[i] += t[j][i];
    }
  }
  cout << solve(0, 0, 0, 0, 0, 0);
}
