#include "bits/stdc++.h"
#pragma GCC optimize("Ofast")
#pragma GCC targetr("avx2")
using namespace std;
using ll = long long;
using pii = pair<int, int>;
vector<pair<vector<pii>, int>> block3 = {
{{{-2, 0}, {-1, 0}, {0, 0}}, 1},
{{{0, 0}, {0, 1}, {0, 2}}, 3},
{{{-1, -1}, {-1, 0}, {0, 0}}, 1},
{{{-1, 1}, {0, 0}, {0, 1}}, 2},
{{{-1, 0}, {0, 0}, {0, 1}}, 2},
{{{-1, 0}, {-1, 1}, {0, 0}}, 2},
};
vector<pair<vector<pii>, int>> block4 = {
{{{-2, 0}, {-2, 1}, {-1, 0}, {0, 0}}, 1},
{{{-2, -1}, {-2, 0}, {-1, 0}, {0, 0}}, 1},
{{{-1, 0}, {-1, 1}, {1, 0}, {1, 0}}, 2},
{{{-2, 1}, {-1, 1}, {0, 0}, {0, 1}}, 2},
{{{-2, 0}, {-1, 0}, {0, 0}, {0, 1}}, 2},
{{{-3, 0}, {-2, 0}, {-1, 0}, {0, 0}}, 1},
{{{0, 0}, {0, 1}, {0, 2}, {0, 3}}, 4},
{{{-1, -1}, {-1, 0}, {0, 0}, {0, 1}}, 2},
{{{-1, 1}, {-1, 2}, {0, 0}, {0, 1}}, 2},
{{{-2, 1}, {-1, 0}, {-1, 1}, {0, 0}}, 1},
{{{-2, -1}, {-1, -1}, {-1, 0}, {0, 0}}, 1},
{{{-1, -1}, {-1, 0}, {-1, 1}, {0, 0}}, 1},
{{{-2, 0}, {-1, -1}, {-1, 0}, {0, 0}}, 1},
{{{-2, 0}, {-1, 0}, {-1, 1}, {0, 0}}, 1},
{{{-1, 1}, {0, 0}, {0, 1}, {0, 2}}, 3},
};
void solve(int TC) {
vector<vector<int>> a(8, vector<int>(8));
vector<vector<char>> board(8, vector<char>(8));
for (int i = 0; i < 8; i++) {
for (int j = 0; j < 8; j++) {
cin >> a[i][j];
board[i][j] = a[i][j] + '0';
}
}
int n;
cin >> n;
vector<string> s(n);
set<string> dict;
for (int i = 0; i < n; i++) {
cin >> s[i];
dict.insert(s[i]);
}
vector dp(9, vector(9, map<ll, ll>()));
dp[0][0][(1ll << 24) - 1]++;
for (int i = 0; i < n; i++) {
for (int j = 0; j < 8; j++) {
for (auto [boardstate, ways]: dp[i][j]) {
vector<vector<bool>> occ(3, vector<bool>(8));
for (int i = 0; i < 3; i++) {
for (int j = 0; j < 8; j++) {
b
}
}
}
}
}
ll ans = dp[8][0][(1ll << 24) - 1];
cout << ans << "\n";
}
int32_t main() {
cin.tie(0)->sync_with_stdio(0);
cout << fixed << setprecision(10);
int t = 1;
// cin >> t;
for (int i = 1; i <= t; i++) {
solve(i);
}
}