#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
#include<cassert>
#include<complex>
using namespace std;

//#define int long long
typedef long long ll;

typedef unsigned long long ul;
typedef unsigned int ui;
const ll mod = 1000000007;
const ll INF = mod * mod;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef pair<ll, ll> LP;
typedef vector<ll> vec;
typedef long double ld;
typedef pair<ld, ld> LDP;
const ld eps = 1e-5;
const ld pi = acos(-1.0);

struct block {
	int h, w;
	vector<vector<char>> b;
};

block b[4];
char ori[4][10];
char cur[4][10];
bool match(int x, int y, int id) {
	//cout << x << " " << y << " " << id << endl;
	int h = b[id].h, w = b[id].w;
	rep(i, h) {
		rep(j, w) {
			if (b[id].b[i][j] == '#') {
				//cout << x + i << " " << y + j << endl;
				if (x + i >= 4 || y + j >= 10)return false;
				if (cur[x + i][y + j] == '#')return false;
			}
		}
	}
	//cout << x << " " << y << " " << id << endl;
	return true;
}
void paint(int x, int y, int id) {
	int h = b[id].h, w = b[id].w;
	rep(i, h) {
		rep(j, w) {
			if (b[id].b[i][j] == '#') {
				cur[x + i][y + j] = '#';
			}
		}
	}
}
void solve() {
	rep(i, 4) {
		cin >> b[i].h >> b[i].w;
		b[i].b.resize(b[i].h);
		
		rep(j, b[i].h) {
			b[i].b[j].resize(b[i].w);
			rep(k, b[i].w) {
				cin >> b[i].b[j][k];
			}
		}
	}
	int n; cin >> n;
	rep(aa, n) {
		rep(i, 4) {
			rep(j, 10) {
				cin >> ori[i][j];
			}
		}
		vector<int> a = { 0,1,2,3 };
		string ans = "No";
		while (true) {
			int id = 0;
			rep(i, 4)rep(j, 10)cur[i][j] = ori[i][j];
			bool valid = true;
			rep(i, 4) {
				rep(j, 10) {
					if (match(i, j, a[id])) {
						paint(i, j, a[id]); id++;
					}
					if (cur[i][j] == '.') {
						valid = false; break;
					}
				}
				if (!valid)break;
			}
			if (valid) {
				ans = "Yes"; break;
			}
			if (!next_permutation(a.begin(), a.end()))break;
		}
		cout << ans << endl;
	}
}

signed main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	solve();
	//stop
	return 0;
}


