#include<bits/stdc++.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define HUGE_NUM 1000000000000000000
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;


#define SIZE 25

struct LOC{
	LOC(int arg_row,int arg_col){
		row = arg_row;
		col = arg_col;
	}
	int row,col;
};

struct Info{

	int num_tile;
	vector<LOC> V[4];
};

int H,W;
int N,POW[12];
int TABLE[SIZE][SIZE],ARRAY[10];
char table[SIZE][SIZE],work[SIZE][SIZE];
bool ans[1024],used[10];
vector<LOC> MAP;
Info info[10];


bool rangeCheck(int row,int col){

	return row >= 0 && row <= H-1 && col >= 0 && col <= W-1;
}

void recursive(int index,int row,int col){

	if(row == H){

		int state = 0;
		for(int i = 0; i < index; i++){

			state += POW[ARRAY[i]];
		}
		ans[state] = true;
		return;
	}

	int next_row = row;
	int next_col = col+1;

	if(col == W-1){

		next_row = row+1;
		next_col = 0;
	}

	if(TABLE[row][col] != 0){

		recursive(index,next_row,next_col);
		return;
	}

	//TABLE[row][col] == 0 //空きマス


	for(int a = 0; a < N; a++){

		if(used[a])continue;

		int id = a;

		for(int i = 0; i < 4; i++){
			if(info[id].V[i].size() == 0)continue;
			bool FLG = true;
			for(int k = 0; k < info[id].num_tile; k++){

				if(!rangeCheck(row+info[id].V[i][k].row,col+info[id].V[i][k].col)){
					FLG = false;
					break;
				}
				if(TABLE[row+info[id].V[i][k].row][col+info[id].V[i][k].col] != 0){
					FLG = false;
					break;
				}
			}
			if(!FLG)continue;

			for(int k = 0; k < info[id].num_tile; k++){

				TABLE[row+info[id].V[i][k].row][col+info[id].V[i][k].col]++;
			}
			used[a] = true;
			ARRAY[index] = a;
			recursive(index+1,next_row,next_col);
			used[a] = false;
			for(int k = 0; k < info[id].num_tile; k++){

				TABLE[row+info[id].V[i][k].row][col+info[id].V[i][k].col]--;
			}
		}
	}
}

void func(){

	MAP.clear();

	for(int row = 0; row < H; row++){
		scanf("%s",table[row]);
		for(int col = 0; col < W; col++){
			if(table[row][col] == '.'){
				MAP.push_back(LOC(row,col));
			}
		}
	}

	scanf("%d",&N);

	for(int i = 0; i < N; i++){
		for(int k = 0; k < 4; k++){
			info[i].V[k].clear();
		}
	}

	int h,w;
	int base_row,base_col;

	for(int i = 0; i < N; i++){

		for(int row = 0; row < max(H,W); row++){
			for(int col = 0; col < max(H,W); col++){
				table[row][col] = '.';
			}
		}
		scanf("%d %d",&h,&w);
		for(int row = 0; row< h; row++){
			scanf("%s",work[row]);
			for(int col = 0; col < w; col++){
				if(work[row][col] == '#'){

					table[row][col] = '#';
				}
			}
		}

		for(int loop = 0; loop < 4; loop++){

			for(int row = 0; row < max(H,W); row++){
				for(int col = 0; col < max(H,W); col++){
					work[row][col] = '.';
				}
			}
			//90度回転
			for(int row = 0; row < max(H,W); row++){
				for(int col = 0; col < max(H,W); col++){
					work[col][W-1-row] = table[row][col];
				}
			}

			bool FLG = false;

			for(int row = 0; row < max(H,W); row++){
				for(int col = 0; col < max(H,W); col++){
					if(work[row][col] == '.')continue;

					if(!FLG){
						base_row = row;
						base_col = col;
						FLG = true;
					}
					info[i].V[loop].push_back(LOC(row-base_row,col-base_col));
				}
			}

			for(int row = 0; row < max(H,W); row++){
				for(int col = 0; col < max(H,W);col++){
					table[row][col] = work[row][col];
				}
			}
		}

		for(int a = 0; a < 3; a++){
			for(int b = a+1; b < 4; b++){
				bool FLG = true;
				for(int k = 0; k < info[i].V[a].size();k++){
					if(info[i].V[a][k].row != info[i].V[b][k].row || info[i].V[a][k].col != info[i].V[b][k].col){
						FLG = false;
						break;
					}
				}
				if(FLG){

					info[i].V[b].clear();
				}
			}
		}

		info[i].num_tile = info[i].V[0].size();
	}

	for(int state = 0; state < POW[N]; state++){

		ans[state] = false;
	}

	for(int i = 0; i < N; i++){
		used[i] = false;
	}
	for(int row = 0; row < H; row++){
		for(int col = 0; col < W; col++){

			TABLE[row][col] = BIG_NUM;
		}
	}
	for(int i = 0; i < MAP.size(); i++){

		TABLE[MAP[i].row][MAP[i].col] = 0;
	}
	recursive(0,0,0);


	int num_query;
	scanf("%d",&num_query);

	int num,tmp;

	for(int i = 0; i < num_query; i++){

		scanf("%d",&num);
		int sum = 0;
		for(int k = 0; k < num; k++){

			scanf("%d",&tmp);
			tmp--;
			sum += POW[tmp];
		}

		if(ans[sum]){

			printf("YES\n");

		}else{

			printf("NO\n");
		}
	}
}


int main(){

	POW[0] = 1;
	for(int i = 1; i < 12; i++){

		POW[i] = POW[i-1]*2;
	}

	while(true){
		scanf("%d %d",&H,&W);
		if(H == 0 && W == 0)break;

		func();
	}

	return 0;
}

