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

void bin(int a){
  rep(i,10){
    if((a>>i)&1)cout << 1;
    else cout << 0;
  }
  cout << endl;
}

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],dif[4];
  vector<int> p[4];
  int num, dir;

  piece(void){}
  piece(vector<string> v){
    int y = v.size(), x = v[0].size();

    num = 0;
    rep(i,y)rep(j,x)if(v[i][j]=='#')num++;

    dir = 0;
    rep(d,4){
      vector<int> vi =  vstovi(v);
      bool f = true;
      rep(i,dir){
	if(p[i] == vi){
	  f = false;
	  break;
	}
      }
      
      if(f){
	p[dir] = vi;
	h[dir] = v.size(); w[dir] = v[0].size();
	rep(i,w[dir]){
	  if(v[0][i]=='#'){
	    dif[dir] = i;
	    break;
	  }
	}
	dir++;
      }
      v = right_rot(v);
    }
  }
  
  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;
int memo[1<<10];
bool can[20][20][10][4];

void set(void){
  rep(i,H)rep(j,W){
    if((board[i]>>j)&1)continue;

    rep(id,n)rep(d,p[id].dir){
      if(i+p[id].h[d]-1>=H)continue;
      if(j+p[id].w[d]-1-p[id].dif[d]>=W)continue;
      if(j<p[id].dif[d])continue;

      bool f = true;
      rep(ii,p[id].h[d]){
	if( (board[i+ii]>>(j-p[id].dif[d])) & p[id].p[d][ii]){
	  f = false;
	  goto END;
	}
      }
    END:;
      can[i][j][id][d] = f;
    }
  }
}

bool rec(int y, int x, int bit){
  while(y<H && ((board[y]>>x)&1)){
    x++;
    if(x>=W){x = 0; y++;}
  }
  if(y==H)return true;

  vector<int> hoge;

  rep(id,n)rep(d,p[id].dir){
    if( ((bit>>id)&1) && can[y][x][id][d]){
      bool f = true;
      rep(i,p[id].h[d]){
	if( (board[y+i] >> (x-p[id].dif[d])) & p[id].p[d][i] ){
	  f = false;
	  goto END;
	}
      }
    END:;
      if(f){
	hoge = board;
	rep(i,p[id].h[d])board[y+i] |= (p[id].p[d][i] << (x-p[id].dif[d]));
	f = rec(y,x,bit&(~(1<<id)));
	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);
    }

    rep(i,H)rep(j,W){
      rep(id,n)rep(d,4)can[i][j][id][d] = false;
    }
    set();

    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;
      }
      
      if(num != space){
	cout << "No\n";
	continue;
      }
      
      if(memo[id]>=0){
	if(memo[bit])cout << "Yes\n";
	else cout << "No\n";
	continue;
      }
      
      bool f = rec(0,0,bit);
      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;
      }
    }
  }
}