#include<bits/stdc++.h>
using namespace std;
#define lp(i,n) for(int i=0;i<n;i++)
#define lps(i,j,n) for(int i=j;i<n;i++)
#define fordebug int hoge;cin>>hoge;
#define DEKAI 1000000007
#define INF 2000000000000
#define int long long
#define double long double
#define floot10 cout<<fixed<<setprecision(10)
#define Int long long
#define ALL(n) n.begin(),n.end()
#define hogea pair<pair<int,int>,int>

struct field{
  string s[4];
  field(){};
  field(string s1,string s2,string s3,string s4){
    s[0]=s1;
    s[1]=s2;
    s[2]=s3;
    s[3]=s4;
  };
};

string ms(field f){
  string s=f.s[0]+f.s[1]+f.s[2]+f.s[3];
  return s;
}

struct teto{
  string s[4];
  int h,w;
};

teto t[4];
set<string> lis;

void revs(int n){
  teto x;
  x.h=t[n].w;
  x.w=t[n].h;
  lp(i,x.h){
    string s="";
    lp(j,t[n].h){
      s=s+t[n].s[j].substr(i,1);
    }
    x.s[i]=s;
  }
  t[n]=x;
}

field br(field f,int n,int x,int y){
  for(int i=x;i<x+t[n].h;i++){
    for(int j=y;j<y+t[n].w;j++){
      if(t[n].s[i-x][j-y]=='#'){
	f.s[i][j]='.';
      }
    }
  }
  return f;
}

bool brcheck(field f,int n,int x,int y){
  for(int i=x;i<x+t[n].h;i++){
    if(i>=4)return false;
    for(int j=y;j<y+t[n].w;j++){
      if(j>=10)return false;
      if(t[n].s[i-x][j-y]=='#'){
	if(f.s[i][j]=='.')return false;
      }
    }
  }
  return true;
}

int popcount(int n){
  int cnt=0;
  lp(i,64){
    if(n&(1<<1))cnt++;
  }
  return cnt;
}

void DBD(field f){
  lp(i,4){
    cout<<f.s[i]<<endl;
  }
  return;
}

void hoge(field f,int b){
  if(__builtin_popcount(b)==3){
    lis.insert(ms(f));
    /*DBD(f);
    int hoge;
    cin>>hoge;*/
    return;
  }
  lp(z,4){
    if(b&(1<<z))continue;
    lp(i,10){
      lp(j,10){
	if(brcheck(f,z,i,j)){
	  hoge(br(f,z,i,j),b|(1<<z));
	}
      }
    }
  }
}

void make(){
  field f("##########","##########","##########","##########");
  hoge(f,0);
}

signed main(){
  lp(i,4){
    int h,w;
    cin>>h>>w;
    t[i].h=h;
    t[i].w=w;
    lp(j,h){
      string s;
      cin>>s;
      t[i].s[j]=s;
    }
  }
  make();
  int n;
  cin>>n;
  lp(i,n){
    string s[4];
    lp(j,4){
      cin>>s[j];
    }
    field f(s[0],s[1],s[2],s[3]);
    if(lis.find(ms(f))==lis.end()){
      cout<<"No"<<endl;
    }
    else cout<<"Yes"<<endl;
  }
  return 0;
}

