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 = 200009;
const int MOD = 1e9 + 7;
string s[1111];
int dp[1111][5][5][5][5];
int cost[5][5][5][5];
int main() {
  ios_base::sync_with_stdio(false), cout.tie(0), cin.tie(0);
  int n;
  cin >> n;
  int cs[5];
  for (int i = 1; i <= 4; ++i) cin >> cs[i];
  cs[0] = 0;
  cin >> s[0] >> s[1] >> s[2] >> s[3];
  for (int i = 0; i < 1111; ++i)
    for (int j = 0; j < 5; ++j)
      for (int jj = 0; jj < 5; ++jj)
        for (int jjj = 0; jjj < 5; ++jjj)
          for (int jjjj = 0; jjjj < 5; ++jjjj) dp[i][j][jj][jjj][jjjj] = 1e9;
  for (int a1 = 0; a1 < 5; ++a1)
    for (int a2 = 0; a2 < 5; ++a2)
      for (int a3 = 0; a3 < 5; ++a3)
        for (int a4 = 0; a4 < 5; ++a4) cost[a1][a2][a3][a4] = 1e9;
  cost[0][0][0][0] = 0;
  for (int a1 = 0; a1 <= 4; ++a1) {
    for (int a2 = 0; a2 <= 3; ++a2) {
      for (int a3 = 0; a3 <= 2; ++a3) {
        for (int a4 = 0; a4 <= 1; ++a4) {
          vector<int> G(4);
          for (int i = 0; i < a1; ++i) G[i] = max(G[i], a1);
          for (int i = 1; i < 1 + a2; ++i) G[i] = max(G[i], a2);
          for (int i = 2; i < 2 + a3; ++i) G[i] = max(G[i], a3);
          for (int i = 3; i < 3 + a4; ++i) G[i] = max(G[i], a4);
          cost[G[0]][G[1]][G[2]][G[3]] = min(cost[G[0]][G[1]][G[2]][G[3]],
                                             cs[a1] + cs[a2] + cs[a3] + cs[a4]);
        }
      }
    }
  }
  auto cal = [](char c, int a1, int b1) {
    if (a1 == 0) {
      if (b1 == 0) {
        return c == '*' ? 1 : 0;
      } else {
        return b1 + 1;
      }
    } else {
      if (a1 - 1 >= b1)
        return 0;
      else
        return b1 + 1;
    }
  };
  dp[n][0][0][0][0] = 0;
  for (int i = n - 1; i >= 0; --i) {
    for (int a1 = 0; a1 <= 4; ++a1) {
      for (int a2 = 0; a2 <= 4; ++a2) {
        for (int a3 = 0; a3 <= 4; ++a3) {
          for (int a4 = 0; a4 <= 4; ++a4) {
            for (int b1 = 0; b1 < 4; ++b1) {
              for (int b2 = 0; b2 < 4; ++b2) {
                for (int b3 = 0; b3 < 4; ++b3) {
                  for (int b4 = 0; b4 < 4; ++b4) {
                    int res1, res2, res3, res4;
                    res1 = cal(s[0][i], a1, b1);
                    res2 = cal(s[1][i], a2, b2);
                    res3 = cal(s[2][i], a3, b3);
                    res4 = cal(s[3][i], a4, b4);
                    dp[i][res1][res2][res3][res4] =
                        min(dp[i][res1][res2][res3][res4],
                            dp[i + 1][b1][b2][b3][b4] + cost[a1][a2][a3][a4]);
                  }
                }
              }
            }
          }
        }
      }
    }
  }
  cout << dp[0][0][0][0][0] << '\n';
  return 0;
}
