#include #include #include #include using namespace std; const int MAX_SIZE = 128; int b_width; int b_height; int f_width; int f_height; bool block[MAX_SIZE][MAX_SIZE]; bool field[MAX_SIZE][MAX_SIZE]; void Rotate() { bool cp[MAX_SIZE][MAX_SIZE]; memcpy(cp, block, sizeof(block)); swap(b_width, b_height); for(int y = 0; y < b_height; ++y) for(int x = 0; x < b_width; ++x) block[x][y] = cp[b_height-y-1][x]; } bool Check(int px, int py) { for(int x = 0; x < b_width; ++x) for(int y = 0; y < b_height; ++y) if(block[x][y]) { int fx = px + x, fy = py + y; if(fx < 0 || f_width <= fx || fy < 0 || f_height <= fy || field[fx][fy]) return false; } return true; } int Count(int px, int py) { int line = 0; for(int y = py; y < min(py+b_height, f_height); ++y) { int cell = 0; for(int x = 0; x < f_width; ++x) { int bx = x - px; if(field[x][y] || (0 <= bx && bx < b_width && block[bx][y-py])) ++cell; } if(cell == f_width) ++line; } return line; } int main() { int nnn; cin >> nnn; for(int iii = 0; iii < nnn; ++iii) { char ch; cin >> b_height >> b_width; for(int y = 0; y < b_height; ++y) for(int x = 0; x < b_width; ++x) { cin >> ch; block[x][y] = (ch == '#'); } cin >> f_height >> f_width; for(int y = 0; y < f_height; ++y) for(int x = 0; x < f_width; ++x) { cin >> ch; field[x][y] = (ch == '#'); } int ans = -1; for(int r = 0; r < 4; ++r) { Rotate(); for(int px = -b_width; px < f_width; ++px) for(int py = -b_height; py < f_height; ++py) { if(Check(px, py)) { //cout << px << py << endl; ans = max(ans, Count(px, py)); } } } cout << ans << endl; } }