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, a[5], b[5], c[5];
char s[10][1020];
int f[1020][257];
void dfs(int i, int x, int w) {
  if (x == 4) {
    for (int i = 0; i < 4; i++) {
      if (c[i] >= 4) {
        return;
      }
    }
    int u = 0;
    for (int i = 0; i < 4; i++) {
      u |= c[i] << (2 * i);
    }
    f[i + 1][u] = min(f[i + 1][u], w);
    return;
  }
  c[x] = b[x];
  dfs(i, x + 1, w);
  if (x < 4 && b[x] <= 1) {
    c[x] = 0;
    dfs(i, x + 1, w + a[1]);
  }
  if (x < 3 && b[x] <= 2 && b[x + 1] <= 2) {
    c[x] = 0;
    c[x + 1] = 0;
    dfs(i, x + 2, w + a[2]);
    dfs(i, x + 1, w + a[2]);
  }
  if (x < 2 && b[x] <= 3 && b[x + 1] <= 3 && b[x + 2] <= 3) {
    c[x] = 0;
    c[x + 1] = 0;
    c[x + 2] = 0;
    dfs(i, x + 3, w + a[3]);
    dfs(i, x + 2, w + a[3]);
    dfs(i, x + 1, w + a[3]);
  }
  if (x < 1 && b[x] <= 4 && b[x + 1] <= 4 && b[x + 2] <= 4 && b[x + 3] <= 4) {
    c[x] = 0;
    c[x + 1] = 0;
    c[x + 2] = 0;
    c[x + 3] = 0;
    dfs(i, x + 4, w + a[4]);
    dfs(i, x + 3, w + a[4]);
    dfs(i, x + 2, w + a[4]);
    dfs(i, x + 1, w + a[4]);
  }
}
int main() {
  scanf("%d%d%d%d%d", &n, &a[1], &a[2], &a[3], &a[4]);
  for (int i = 0; i < 4; i++) {
    scanf("%s", s[i]);
  }
  memset(f, 0x3f, sizeof f);
  f[0][0] = 0;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < 256; j++) {
      if (f[i][j] == 0x3f3f3f3f) {
        continue;
      }
      int u = j;
      for (int k = 0; k < 4; k++) {
        b[k] = u % 4;
        u /= 4;
      }
      for (int k = 0; k < 4; k++) {
        if (s[k][i] == '*' || b[k] > 0) {
          b[k]++;
        }
      }
      dfs(i, 0, f[i][j]);
    }
  }
  printf("%d\n", f[n][0]);
  return 0;
}
