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;
long long readi() {
  long long input = 0;
  char c = ' ';
  while (c < '-') {
    c = getchar();
  }
  bool negative = false;
  if (c == '-') {
    negative = true;
    c = getchar();
  }
  while (c >= '0') {
    input = 10 * input + (c - '0');
    c = getchar();
  }
  if (negative) {
    input = -input;
  }
  return input;
}
void printi(long long output) {
  if (output == 0) {
    putchar('0');
    return;
  }
  if (output < 0) {
    putchar('-');
    output = -output;
  }
  int aout[20];
  int ilen = 0;
  while (output) {
    aout[ilen] = ((output % 10));
    output /= 10;
    ilen++;
  }
  for (int i = ilen - 1; i >= 0; i--) {
    putchar(aout[i] + '0');
  }
  return;
}
string reads() {
  string input = "";
  char c = ' ';
  while (c <= ' ') {
    c = getchar();
  }
  while (c > ' ') {
    input += c;
    c = getchar();
  }
  return input;
}
int sgn(long long x) {
  if (x < 0) {
    return -1;
  }
  if (x > 0) {
    return 1;
  }
  return 0;
}
long long randomize(long long mod) {
  return ((1 << 30) * rand() + (1 << 15) * rand() + rand()) % mod;
}
const long double PI = 4.0 * atan(1.0);
const long double EPS = 1e-30;
long long normalize(long long x, long long mod) {
  return (((x % mod) + mod) % mod);
}
int N;
int grid[1010];
int cost[6];
int dp[2][4100];
int ans;
int comb(int a, int b) { return a & (4095 - b); }
int32_t main() {
  ios_base::sync_with_stdio(0);
  srand(time(0));
  if (fopen("cf903f.in", "r")) {
    freopen("cf903f.in", "r", stdin);
    freopen("cf903f.out", "w", stdout);
  }
  cin >> N;
  for (int i = 1; i <= 4; i++) {
    cin >> cost[i];
  }
  cost[5] = 1000000007;
  for (int i = 4; i >= 0; i--) {
    cost[i] = min(cost[i], cost[i + 1]);
  }
  for (int i = 0; i < 4; i++) {
    string s;
    cin >> s;
    for (int j = 0; j < N; j++) {
      if (s[j] == '*') {
        grid[j] += (1 << i);
      }
    }
  }
  for (int i = 0; i < 2; i++) {
    for (int j = 0; j < (1 << 12); j++) {
      dp[i][j] = 1000000007;
    }
  }
  dp[0][0] = 0;
  for (int i = 0; i <= N + 2; i++) {
    for (int j = 0; j < (1 << 12); j++) {
      if (j & 3840) {
        dp[1][0] = min(dp[1][0], dp[0][j] + cost[4]);
        continue;
      }
      for (int k = 0; k < 96; k++) {
        int temp = k, mask = 16 * j + grid[i], curcost = 0;
        for (int m = 3; m >= 0; m--) {
          int val = temp % (5 - m);
          temp /= (5 - m);
          curcost += cost[val];
          if (val == 0) {
            continue;
          }
          if (val == 1) {
            mask = comb(mask, (1 << m));
          }
          if (val == 2) {
            mask = comb(mask, (1 << m) * 51);
          }
          if (val == 3) {
            mask = comb(mask, (1 << m) * 1911);
          }
        }
        assert(mask <= 4095);
        dp[1][mask] = min(dp[1][mask], dp[0][j] + curcost);
      }
    }
    for (int j = 0; j < (1 << 12); j++) {
      dp[0][j] = dp[1][j];
      dp[1][j] = 1000000007;
    }
  }
  ans = dp[0][0];
  cout << ans << '\n';
}
