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

struct pos{
  int y,x,d;
  pos(int a=0,int b=0,int c=0):y(a),x(b),d(c){}
};

struct piece{
  int h,w;
  vector<string> p[4];
  int num;
  vector<pos> can;

  piece(int a=0,int b=0,vector<string> c=vector<string>()):h(a),w(b){
    num = 0;
    rep(i,h)rep(j,w)if(c[i][j]=='#')num++;

    p[0] = c;
  
    p[1].resize(w);
    rep(i,w)p[1][i].resize(h);
    rep(i,h)rep(j,w)p[1][j][h-1-i] = p[0][i][j];

    p[2].resize(h);
    rep(i,h)p[2][i].resize(w);
    rep(i,h)rep(j,w)p[2][h-1-i][w-1-j] = p[0][i][j];

    p[3].resize(w);
    rep(i,w)p[3][i].resize(h);
    rep(i,h)rep(j,w)p[3][w-1-j][i] = p[0][i][j];
  }
  
  void set(int H,int W, vector<string> board){
    rep(d,4){
      rep(i,H-(int)p[d].size()+1)rep(j,W-(int)p[d][0].size()+1){
	bool f = true;
	rep(ii,p[d].size())rep(jj,p[d][0].size()){
	  if(board[i+ii][j+jj] == '#' && p[d][ii][jj] == '#'){
	    f = false;
	    goto END;
	  }
	}
      END:;
	if(f)can.push_back(pos(i,j,d));
      }
    }
  }

  bool operator<(const piece x)const{return num>x.num;}
};

int H,W;
vector<string> board,tmp;
int h,w,n,player;
piece p[10];
int k,id;
piece v[10];

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

  depth--;
  vector<string> hoge;
  rep(z,v[depth].can.size()){
    int y = v[depth].can[z].y, x = v[depth].can[z].x, d = v[depth].can[z].d;
    int height = v[depth].p[d].size(), width = v[depth].p[d][0].size();

    bool f = true;
    rep(i,height)rep(j,width){
      if(board[y+i][x+j] == '#' && v[depth].p[d][i][j] == '#'){
	f = false;
	goto END;
      }
    }
  END:;
    if(f){
      hoge = board;
      rep(i,height)rep(j,width){
	if(v[depth].p[d][i][j] == '#'){
	  board[y+i][x+j] = '#';
	}
      }
      bool f = rec(depth);
      board = hoge;
      if(f)return true;
    }
  }
  return false;
}
  

int main(){
  cin.tie(0);
  std::ios::sync_with_stdio(false);

  while(cin >> H >> W,H||W){
    board.resize(H);
    int space = 0;
    rep(i,H){
      cin >> board[i];
      rep(j,W)if(board[i][j]=='.')space++;
    }

    cin >> n;
    rep(i,n){
      cin >> h >> w;
      tmp.resize(h);
      rep(j,h)cin >> tmp[j];
      p[i] = piece(h,w,tmp);
      p[i].set(H,W,board);
    }

    cin >> player;
    rep(i,player){
      cin >> k;
      int num = 0;

      rep(j,k){
	cin >> id; id--;
	num += p[id].num;
	v[j] = p[id];
      }

      if(num != space){
	cout << "No\n";
	continue;
      }

      sort(v,v+k);
      if(rec(k))cout << "Yes\n";
      else cout << "No\n";
    }
  }
}