#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){}
};

vector<string> right_rot(vector<string> v){
  vector<string> res;
  int h = v.size(), w = v[0].size();
  res.resize(w);
  rep(i,w)res[i].resize(h);
  rep(i,h)rep(j,w)res[j][h-1-i] = v[i][j];
  return res;
}

vector<int> vstovi(vector<string> v){
  vector<int> res;
  rep(i,v.size()){
    int tmp = 0;
    rep(j,v[i].size())
      if(v[i][j] == '#')tmp |= 1<<j;
    res.push_back(tmp);
  }
  return res;
}

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

  piece(void){}
  piece(vector<string> c){
    int a = c.size(), b = c[0].size();
    rep(i,4){
      if(i&1){h[i] = b; w[i] = a;}
      else{h[i] = a; w[i] = b;}
    }

    num = 0;
    rep(i,h[0])rep(j,w[0])if(c[i][j]=='#')num++;

    p[0] = vstovi(c);

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

  bool operator<(const piece x)const{return h[0]*w[0]<x.h[0]*x.w[0];}
};

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

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

  depth--;
  vector<int> 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].h[d], width = v[depth].w[d];

    bool f = true;
    rep(i,height){
      if( (board[y+i]>>x) & v[depth].p[d][i]){
	f = false;
	goto END;
      }
    }
  END:;
    if(f){
      hoge = board;
      rep(i,height)board[y+i] |= (v[depth].p[d][i] << x);
      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){
    tmp.resize(H);
    int space = 0;
    rep(i,H){
      cin >> tmp[i];
      rep(j,W)if(tmp[i][j]=='.')space++;
    }
    board = vstovi(tmp);

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

    rep(i,1<<10)memo[i] = -1;

    cin >> player;
    rep(i,player){
      cin >> k;
      int num = 0;
      
      int bit = 0;
      rep(j,k){
	cin >> id; id--;
	bit |= (1<<id);
	num += p[id].num;
	v[j] = p[id];
      }
      
      if(num != space){
	cout << "No\n";
	continue;
      }
      
      if(memo[id]>=0){
	if(memo[bit])cout << "Yes\n";
	else cout << "No\n";
	continue;
      }

      sort(v,v+k);
      bool f = rec(k);
      if(f){
	cout << "Yes\n";
	rep(j,1<<10){
	  if( (j&bit) == bit )memo[j] = 0;
	  else if( (j&bit) == j )memo[j] = 0;
	}
	memo[bit] = 1;
      }else{
	cout << "No\n";
	memo[bit] = 0;
      }
    }
  }
}