#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <set>
using namespace std;

int main(){
    vector<int> h(4), w(4);
    vector< vector<string> > s(4, vector<string>(4));
    for(int i=0; i<4; i++){
        cin>>h[i]>>w[i];
        vector<string> S(h[i]);
        for(int j=0; j<h[i]; j++){
            cin>>S[j];
        }
        s[i] = S;
    }

    set<vector<string>> exist;

    vector<int> v = {0, 1, 1, 1};
    do{
        vector<int> useid;
        for(int i=0; i<4; i++){
            if(v[i] == 1) useid.emplace_back(i);
        }

        int aid = useid[0];
        int bid = useid[1];
        int cid = useid[2];

        for(int ax=0; ax+w[aid]-1<10; ax++){
            for(int ay=0; ay+h[aid]-1<4; ay++){
                for(int bx=0; bx+w[bid]-1<10; bx++){
                    for(int by=0; by+h[bid]-1<4; by++){
                        for(int cx=0; cx+w[cid]-1<10; cx++){
                            for(int cy=0; cy+h[cid]-1<4; cy++){
                                
                                vector<string> ban(4);
                                for(int i=0; i<4; i++){
                                    ban[i] = "..........";
                                }

                                int ayt = ay + h[aid] - 1;
                                int axt = ax + w[aid] - 1;
                                int byt = by + h[bid] - 1;
                                int bxt = bx + w[bid] - 1;
                                int cyt = cy + h[cid] - 1;
                                int cxt = cx + w[cid] - 1;

                                bool valid = true;
                                for(int ady=ay; ady<=ayt; ady++){
                                    for(int adx=ax; adx<=axt; adx++){
                                        if(ban[ady][adx] == '#'){
                                            if(s[aid][ady-ay][adx-ax] == '.');
                                            else valid = false;
                                        }
                                        else{
                                            ban[ady][adx] = s[aid][ady-ay][adx-ax];
                                        }

                                        if(!valid) break;
                                    }
                                    
                                    if(!valid) break;
                                }

                                if(!valid) continue;

                                for(int bdy=by; bdy<=byt; bdy++){
                                    for(int bdx=bx; bdx<=bxt; bdx++){
                                        if(ban[bdy][bdx] == '#'){
                                            if(s[bid][bdy-by][bdx-bx] == '.');
                                            else valid = false;
                                        }
                                        else{
                                            ban[bdy][bdx] = s[bid][bdy-by][bdx-bx];
                                        }

                                        if(!valid) break;
                                    }

                                    if(!valid) break;
                                }

                                if(!valid) continue;

                                for(int cdy=cy; cdy<=cyt; cdy++){
                                    for(int cdx=cx; cdx<=cxt; cdx++){
                                        if(ban[cdy][cdx] == '#'){
                                            if(s[cid][cdy-cy][cdx-cx] == '.');
                                            else valid = false;
                                        }
                                        else{
                                            ban[cdy][cdx] = s[cid][cdy-cy][cdx-cx];
                                        }

                                        if(!valid) break;
                                    }

                                    if(!valid) break;
                                }

                                if(!valid) continue;

                                for(int i=0; i<4; i++){
                                    for(int j=0; j<10; j++){
                                        ban[i][j] = (ban[i][j] == '.' ? '#' : '.');
                                    }
                                }

                                exist.emplace(ban);
                            }
                        }
                    }
                }
            }
        }
    }while(next_permutation(v.begin(), v.end()));

    int n; cin>>n;
    while(n--){
        vector<string> B(4);
        for(int i=0; i<4; i++) cin>>B[i];

        if(exist.count(B)) cout << "Yes" << endl;
        else cout << "No" << endl;
    }
}


Measured memory_bytes: 9548