#include "bits/stdc++.h"
#include<unordered_map>
#include<unordered_set>
#pragma warning(disable:4996)
using namespace std;
using ld = long double;
template<class t>
using table = vector<vector<t>>;
const ld eps=1e-9;

//// < "d:\d_download\visual studio 2015\projects\programing_contest_c++\debug\a.txt"


vector<vector<int>>rotate(const vector<vector<int>>&field) {
	vector<vector<int>>newfield(field[0].size(), vector<int>(field.size()));
	for (int y = 0; y < field.size(); ++y) {
		for (int x = 0; x < field[0].size(); ++x) {
			newfield[y][x] = field[field[0].size() - x - 1][y];
		}
	}
	return newfield;
}
struct piece_ob {
	vector<vector<int>>pob;
	int ulx, uly;
	piece_ob(const vector<vector<int>>&pob_):pob(pob_) {
		for (int y = 0; y < pob.size(); ++y) {
			for (int x = 0; x < pob[0].size(); ++x) {
				if (pob[y][x]) {
					uly = y;
					ulx = x;
					return;
				}
			}
		}
	}
};
struct piece {
	vector<piece_ob>pis;
};
vector<piece>pieces;

bool check(const vector<vector<int>>&field,set<int>&rest) {
	for (int y = 0; y < field.size(); ++y) {
		for (int x = 0; x < field[0].size(); ++x) {
			if (!field[y][x]) {
				bool aok = true;
				for (auto r : rest) {
					for (int i = 0; i < 4; ++i) {
						piece_ob p(pieces[r].pis[i]);
						for (int dy = 0; dy < p.pob.size(); ++dy) {
							const int ay = y + dy - p.uly;
							for (int dx = 0; dx < p.pob[0].size(); ++dx) {
								const int ax = x + dx - p.ulx;
								if (p.pob[dy][dx]) {
									if(ay>=0&&a)
								}
							}
						}

					}

				}
			}
		}
	}
}

int main() {
	int H, W; cin >> H >> W;
	vector<vector<int>>base(H, vector<int>(W));
	for (int y = 0; y < H; ++y) {
		string st; cin >> st;
		for (int x = 0; x < W; ++x) {
			if (st[x] == '#')base[y][x] = true;

		}
	}
	int N; cin >> N;
	for (int i = 0; i < N; ++i) {
		int H,W; cin >> H >> W;
		vector<vector<int>>apiece(H, vector<int>(W));
		for (int y = 0; y < H; ++y) {
			string st; cin >> st;
			for (int x = 0; x < W; ++x) {
				if (st[x] == '#')apiece[y][x] = true;
			}
		}
		piece p;
		for (int j = 0; j < 4; ++j) {
			piece_ob ob(apiece);
			p.pis.push_back(ob);
			apiece = rotate(apiece);
		}
		pieces.push_back(p);
	}
	int P; cin >> P;
	for (int i = 0; i < P; ++i) {
		int K; cin >> K;
		for (int j = 0; j < K; ++j) {
			int a; cin >> a;
		}
	}
	return 0;
}