#include <iostream>
#include <string>
#include <vector>
#include <array>

using namespace std;

int rows;
int cols;
int poscount = 0;
array<int, 4> cnt;
vector<string> table;

void solve(int kind, int curr, int curc)
{
    char ship;
    int k = 0;
    for (; k < 4; ++k) {
        if (cnt[k] > 0) break;
    }
    if (k == 4) {
        ++poscount;
        return;
    }
    ++curc;
    if (curc == cols) {
        curc = 0;
        ++curr;
    }
    if (k != kind) {
        curr = 0;
        curc = 0;
    }
    for (int r = curr; r < rows; ++r) {
        for (int c = curc; c < cols; ++c) {
            curc = 0;
            if (table[r][c] != '#') continue;

            if (k == 0) {
                // 4 deck
                if (c + 3 < cols && table[r][c+1] == '#' && table[r][c+2] == '#' && table[r][c+3] == '#') {
                    ship = '4';
                    table[r][c] = ship;
                    table[r][c+1] = ship;
                    table[r][c+2] = ship;
                    table[r][c+3] = ship;
                    --cnt[k];
                    solve(k, r, c);
                    ++cnt[k];
                    table[r][c+3] = '#';
                    table[r][c+2] = '#';
                    table[r][c+1] = '#';
                    table[r][c] = '#';
                }
                if (r + 3 < rows && table[r+1][c] == '#' && table[r+2][c] == '#' && table[r+3][c] == '#') {
                    ship = '4';
                    table[r][c] = ship;
                    table[r+1][c] = ship;
                    table[r+2][c] = ship;
                    table[r+3][c] = ship;
                    --cnt[k];
                    solve(k, r, c);
                    ++cnt[k];
                    table[r][c] = '#';
                    table[r+1][c] = '#';
                    table[r+2][c] = '#';
                    table[r+3][c] = '#';
                }
            } else if (k == 1) {
                // 3 deck
                if (c + 2 < cols && table[r][c+1] == '#' && table[r][c+2] == '#') {
                    ship = '3';
                    table[r][c] = ship;
                    table[r][c+1] = ship;
                    table[r][c+2] = ship;
                    --cnt[k];
                    solve(k, r, c);
                    ++cnt[k];
                    table[r][c+2] = '#';
                    table[r][c+1] = '#';
                    table[r][c] = '#';
                }
                if (r + 2 < rows && table[r+1][c] == '#' && table[r+2][c] == '#') {
                    ship = '3';
                    table[r][c] = ship;
                    table[r+1][c] = ship;
                    table[r+2][c] = ship;
                    --cnt[k];
                    solve(k, r, c);
                    ++cnt[k];
                    table[r][c] = '#';
                    table[r+1][c] = '#';
                    table[r+2][c] = '#';
                }
            } else if (k == 2) {
                // 2 deck
                if (c + 1 < cols && table[r][c+1] == '#') {
                    ship = '2';
                    table[r][c] = ship;
                    table[r][c+1] = ship;
                    --cnt[k];
                    solve(k, r, c);
                    ++cnt[k];
                    table[r][c+1] = '#';
                    table[r][c] = '#';
                }
                if (r + 1 < rows && table[r+1][c] == '#') {
                    ship = '2';
                    table[r][c] = ship;
                    table[r+1][c] = ship;
                    --cnt[k];
                    solve(k, r, c);
                    ++cnt[k];
                    table[r][c] = '#';
                    table[r+1][c] = '#';
                }
            } else {
                abort();
            }
        }
    }
}

int main()
{
    int n1, n2, n3, n4;

    cin >> n1 >> n2 >> n3 >> n4;
    cin >> rows >> cols;
    if (n1 < 0 || n1 > 4 || n2 < 0 || n2 > 3 || n3 < 0 || n3 > 2 || n4 < 0 || n4 > 1) abort();
    if (rows < 1 || rows > 20 || cols < 1 || cols > 20) abort();

    string buf;
    getline(cin, buf);

    int hashcount = 0;
    for (int i = 0; i < rows; ++i) {
        getline(cin, buf);
        if (cin.eof()) abort();
        if (int(buf.length()) != cols) abort();
        for (char c : buf) hashcount += (c == '#');
        table.push_back(buf);
    }
    getline(cin, buf);
    if (!cin.eof()) abort();
    if (hashcount != n1 + 2 * n2 + 3 * n3 + 4 * n4) abort();

    cnt = array<int, 4>{ n4,n3,n2,0};
    solve(-1, 0, -1);

    cout << poscount << endl;
}
