#include <algorithm>
#include <bitset>
#include <cassert>
#include <chrono>
#include <climits>
#include <cmath>
#include <complex>
#include <cstring>
#include <deque>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#include <cstdint>
using namespace std;
typedef long long ll;
#define MP make_pair
#define PB push_back
#define inf 1000000007
#define mod 1000000007
#define rep(i,n) for(int i = 0; i < (int)(n); ++i)

struct mino{
    int h;
    int w;
    vector<string> s;
    mino(){};
};
mino *t[4];
const int H = 4;
const int W = 10;

bool putable(vector<string> &field,int a,int b,int k){
    int h = t[k]->h;
    int w = t[k]->w;
    vector<string> &s =t[k]->s; 
    rep(i,h){
        if(a+h>H)return false;
        rep(j,w){
            if(b+w>W){
                return false;
            }
            if(s[i][j]=='.')continue;
            int hh = a+i;
            int ww = b+j;
            if(field[hh][ww]=='#')return false;

        }
    }
    //cerr << a << " " << b << " " << k << endl;
    return true;
}
void put(vector<string> &field,int a,int b,int k){
    int h = t[k]->h;
    int w = t[k]->w;
    vector<string> &s =t[k]->s; 
    rep(i,h){
        rep(j,w){
            if(s[i][j]=='.')continue;
            int hh = a+i;
            int ww = b+j;
            field[hh][ww] = '#';
        }
    }
}
void reverse(vector<string> &field,int a,int b,int k){
    int h = t[k]->h;
    int w = t[k]->w;
    vector<string> &s =t[k]->s; 
    rep(i,h){
        rep(j,w){
            if(s[i][j]=='.')continue;
            int hh = a+i;
            int ww = b+j;
            field[hh][ww] = '.';
        }
    }
}
bool ok(vector<string> &field,int ccc,int a,int b){
    int cnt = 0;
    rep(i,4){
        if((ccc>>i)&1)cnt++;
    }
    //cerr << cnt << " " << ccc << " " << a << " " << b << endl;
    if(cnt==3)return true;
    rep(i,4){
        if((ccc>>i)&1){
            
        }else{
            for(int j=a;j<H;j++){
                if(j==a){
                    for(int k=b;k<W;k++){
                        if(putable(field,j,k,i)){
                            put(field,j,k,i);
                            if(ok(field,ccc^(1<<i),j,k)){
                                return true;
                            }
                            reverse(field,j,k,i);
                        }
                    }
                }else{
                    for(int k=0;k<W;k++){
                        if(putable(field,j,k,i)){
                            put(field,j,k,i);
                            if(ok(field,ccc^(1<<i),j,k)){
                                return true;
                            }
                            reverse(field,j,k,i);
                        }
                    }
                }
                
            }




        }
    }
    return false;
}




int main(){
    rep(i,4){
        t[i] = new mino();
    }
    rep(i,4){
        int a,b;
        cin >> a >> b;
        t[i]->h = a;
        t[i]->w = b;
        rep(j,a){
            string s;
            cin >> s;
            t[i]->s.push_back(s);
        }
    }
    int n;
    cin >> n;
    rep(i,n){
        vector<string> field(4);
        rep(j,4){
            cin >> field[j];
        }
        if(ok(field,0,0,0)){
            cout << "Yes" << endl;
        }else{
            cout << "No" << endl;
        }
    }
    return 0;
}


Measured memory_bytes: 3216