#include<iostream>
#include<vector>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;

void bin(int bit){
  for(int i=0;i<20;i++){
    cout << (bit&1);
    bit >>= 1;
  }
  cout << endl;
}

struct piece{
  int h,w,num,dify,difx;
  vector<string> b;

  piece(void){};
  piece(vector<string> v):b(v){
    h = v.size(); w = v[0].size();
    num = 0;
    dify = difx = -1;
    rep(i,h)rep(j,w){
      if(v[i][j] == '#'){
	num++;
	if(dify<0){ dify = i; difx = j; }
      }
    }
  }

  piece rot(void){
    vector<string> tmp;
    tmp.resize(w);
    rep(i,w)tmp[i].resize(h);
    rep(i,h)rep(j,w)tmp[j][h-1-i] = b[i][j];
    return piece(tmp);
  }

  bool operator==(const piece x)const{
    if(h!=x.h || w!=x.w)return false;
    rep(i,h)rep(j,w)if(b[i][j]!=x.b[i][j])return false;
    return true;
  }
};

int n;
piece board;
vector<piece> p[20];

bool rec(int bit){
  if(!bit)return true;

  int y,x;
  rep(i,board.h)rep(j,board.w){
    if(board.b[i][j] == '.'){
      y = i; x = j;
      goto UPLEFT;
    }
  }
 UPLEFT:;
  
  vector<string> tmp;
  rep(i,n){
    if( (bit>>i) & 1 ){
      rep(d,p[i].size()){
	int dy = p[i][d].dify, dx = p[i][d].difx;
	if(y<dy || x<dx)continue;
	int h = p[i][d].h, w = p[i][d].w;
	if(y+h-1-dy>=board.h || x+w-1-dx>=board.w)continue;

	bool f = true;
	rep(ii,h)rep(jj,w){
	  if(board.b[y+ii-dy][x+jj-dx] == '#' && p[i][d].b[ii][jj] == '#'){
	    f = false;
	    goto CHECK;
	  }
	}
      CHECK:;

	if(f){
	  rep(ii,h)rep(jj,w){
	    if(p[i][d].b[ii][jj] == '#')board.b[y+ii-dy][x+jj-dx] = '#';
	  }
	  f = rec(bit - (1<<i));
	  rep(ii,h)rep(jj,w){
	    if(p[i][d].b[ii][jj] == '#')board.b[y+ii-dy][x+jj-dx] = '.';
	  }
	  if(f)return true;
	}
      }
    }
  }
  return false;
}

int main(){
  int h,w,player,k,id;
  vector<string> v;

  while(cin >> h >> w,h||w){
    v.resize(h);
    rep(i,h)cin >> v[i];
    board = piece(v);

    cin >> n;
    rep(i,n){
      cin >> h >> w;
      v.resize(h);
      rep(j,h)cin >> v[j];
      p[i].clear();
      p[i].push_back(piece(v));
      rep(d,3){
	piece tmp = p[i][d].rot();
	bool f = true;
	rep(j,d+1){
	  if(p[i][j] == tmp){
	    f = false;
	    break;
	  }
	}
	if(!f)break;
	p[i].push_back(tmp);
      }
    }

    cin >> player;
    rep(i,player){
      int bit = 0, sum = board.h*board.w - board.num;

      cin >> k;
      rep(j,k){
	cin >> id; id--;
	bit |= 1<<id;
	sum -= p[id][0].num;
	//cout << p[id][0].num << endl;
	//rep(i,p[id][0].h)cout << p[id][0].b[i] << endl;
      }

      //cout << sum << endl;
      if(sum){
	cout << "No\n";
	continue;
      }

      if(rec(bit))cout << "Yes\n";
      else cout << "No\n";
    }
  }
}
      
    