/* Problem URL: https://codeforces.com/contest/903/problem/F */

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;

template <class T, class comp = less<>>
using ordered_set = tree<T, null_type , comp , rb_tree_tag , tree_order_statistics_node_update>;

#define V vector

#define rmin(a, b) a = min(a, b)
#define rmax(a, b) a = max(a, b)

#define rep(i, lim) for (int i = 0; i < (lim); i++)
#define nrep(i, s, lim) for (int i = s; i < (lim); i++)

#define repv(i, v) for (auto &i : (v))
#define fillv(v) for (auto &itr_ : (v)) { cin >> itr_; }
#define sortv(v) sort(v.begin(), v.end())
#define all(v) (v).begin(), (v).end()

using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using vvvvi = vector<vvvi>;

using ll = long long;

using vl = vector<ll>;
using vvl = vector<vl>;
using vvvl = vector<vvl>;
using vvvvl = vector<vvvl>;

template<class v>
auto operator<<(ostream &os, const vector<v> &vec)->ostream& {
    os << vec[0];
    for (size_t i = 1; i < vec.size(); i++) {
        os << ' ' << vec[i];
    }
    os << '\n';
    return os;
}

template<class v>
auto operator>>(istream &is, vector<v> &vec)->istream& {
    for (auto &i : vec) {
        is >> i;
    }
    return is;
}

template<class v>
auto operator<<(ostream &os, const vector<vector<v>> &vec)->ostream& {
    for (auto &i : vec) {
        os << i[0];
        for (size_t j = 1; j < i.size(); j++) {
            os << ' ' << i[j];
        }
        os << '\n';
    }
    return os;
}

template<class v>
auto operator>>(istream  &is, vector<vector<v>> &vec)->istream& {
    for (auto &i : vec) {
        for (auto &j : i) {
            is >> j;
        }
    }
    return is;
}

const int oo = INT32_MAX >> 1;
const ll OO = INT64_MAX >> 1;


void pre()
{

}

#define TEST 0

void solve()
{
    int n;
    cin >> n;

    ll a1, a2, a3, a4;
    cin >> a1 >> a2 >> a3 >> a4;

    V<string> a(4);
    cin >> a;

    vvi c(4, vi(n));

    rep(i, 4) {
        rep(j, n) {
            c[i][j] += a[i][j] == '*';

            if (i > 0) {
                c[i][j] += c[i - 1][j];
            }

            if (j > 0) {
                c[i][j] += c[i][j - 1];
            }

            if (i > 0 && j > 0) {
                c[i][j] -= c[i - 1][j - 1];
            }
        }
    }

    auto get = [&](int x1, int y1, int x2, int y2) {
        int sum = c[y2][x2];

        if (x1 > 0) {
            sum -= c[y2][x1 - 1];
        }

        if (y1 > 0) {
            sum -= c[y1 - 1][x2];
        }

        if (x1 > 0 && y1 > 0) {
            sum += c[y1 - 1][x1 - 1];
        }

        return sum;
    };

    auto case1 = [&](int i) {
        int sum1 = get(i, 0, i, 0) > 0;
        int sum2 = get(i, 1, i, 1) > 0;
        int sum3 = get(i, 2, i, 2) > 0;
        int sum4 = get(i, 3, i, 3) > 0;

        return a1 * (sum1 + sum2 + sum3 + sum4);
    };

    auto case2 = [&](int i) {
        int sum1 = get(i, 0, i + 1, 1) > 0;
        int sum2 = get(i, 2, i + 1, 3) > 0;

        return a2 * (sum1 + sum2);
    };

    auto case3 = [&](int i) {
        int sum1 = get(i, 0, i + 1, 1) > 0;
        int sum2 = get(i, 2, i, 2) > 0;
        int sum3 = get(i + 1, 2, i + 1, 2) > 0;
        int sum4 = get(i, 3, i, 3) > 0;
        int sum5 = get(i + 1, 3, i + 1, 3) > 0;

        return a2 * sum1 + a1 * (sum2 + sum3 + sum4 + sum5);
    };

    auto case4 = [&](int i) {
        int sum1 = get(i, 2, i + 1, 3) > 0;
        int sum2 = get(i, 0, i, 0) > 0;
        int sum3 = get(i + 1, 0, i + 1, 0) > 0;
        int sum4 = get(i, 1, i, 1) > 0;
        int sum5 = get(i + 1, 1, i + 1, 1) > 0;

        return a2 * sum1 + a1 * (sum2 + sum3 + sum4 + sum5);
    };

    auto case5 = [&](int i) {
        int sum1 = get(i, 0, i + 2, 2) > 0;
        int sum2 = get(i, 3, i, 3) > 0;
        int sum3 = get(i + 1, 3, i + 1, 3) > 0;
        int sum4 = get(i + 2, 3, i + 2, 3) > 0;

        return a3 * sum1 + a1 * (sum2 + sum3 + sum4);
    };

    auto case6 = [&](int i) {
        int sum1 = get(i, 1, i + 2, 3) > 0;
        int sum2 = get(i, 0, i, 0) > 0;
        int sum3 = get(i + 1, 0, i + 1, 0) > 0;
        int sum4 = get(i + 2, 0, i + 2, 0) > 0;

        return a3 * sum1 + a1 * (sum2 + sum3 + sum4);
    };

    auto case7 = [&](int i) {
        int sum1 = get(i, 0, i + 2, 2) > 0;
        int sum2 = get(i, 3, i + 1, 3) > 0;
        int sum3 = get(i + 2, 3, i + 2, 3) > 0;

        return sum1 * a3 + sum2 * a2 + sum3 * min(a1, a2);
    };

    auto case8 = [&](int i) {
        int sum1 = get(i, 0, i + 2, 2) > 0;
        int sum2 = get(i + 1, 3, i + 2, 3) > 0;
        int sum3 = get(i, 3, i, 3) > 0;

        return sum1 * a3 + sum2 * a2 + sum3 * min(a1, a2);
    };

    auto case9 = [&](int i) {
        int sum1 = get(i, 1, i + 2, 3) > 0;
        int sum2 = get(i, 0, i + 1, 0) > 0;
        int sum3 = get(i + 2, 0, i + 2, 0) > 0;

        return sum1 * a3 + sum2 * a2 + sum3 * min(a1, a2);
    };

    auto case10 = [&](int i) {
        int sum1 = get(i, 1, i + 2, 3) > 0;
        int sum2 = get(i + 1, 0, i + 2, 0) > 0;
        int sum3 = get(i, 0, i, 0) > 0;

        return sum1 * a3 + sum2 * a2 + sum3 * min(a1, a2);
    };

    auto case11 = [&](int i) {
        int sum1 = get(i, 0, i + 2, 2) > 0;
        int sum2 = get(i, 3, i + 2, 3) > 0;

        return a3 * (sum1 + sum2);
    };

    auto case12 = [&](int i) {
        return a4 * (get(i, 0, i + 3, 3) > 0);
    };

    vl dp(n + 1, OO);
    dp[0] = 0;

    nrep(i, 1, n + 1) {
        rmin(dp[i], dp[i - 1] + case1(i - 1));

        if (i >= 2) {
            rmin(dp[i], dp[i - 2] + case2(i - 2));
            rmin(dp[i], dp[i - 2] + case3(i - 2));
            rmin(dp[i], dp[i - 2] + case4(i - 2));
        }

        if (i >= 3) {
            rmin(dp[i], dp[i - 3] + case5(i - 3));
            rmin(dp[i], dp[i - 3] + case6(i - 3));
            rmin(dp[i], dp[i - 3] + case7(i - 3));
            rmin(dp[i], dp[i - 3] + case8(i - 3));
            rmin(dp[i], dp[i - 3] + case9(i - 3));
            rmin(dp[i], dp[i - 3] + case10(i - 3));
        }

        if (i >= 4) {
            rmin(dp[i], dp[i - 4] + case11(i - 4));
        }
    }

    cout << dp[n] << '\n';
}

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    pre();

    int t;
    (TEST && cin >> t) || (t = 1);
    while (t--) {
        solve();
    }
}
