Language: C++

#include <iostream>
#include <algorithm>
#include <vector>

using namespace std;

int N;
int blH,blW;
int bdH,bdW;
int block[4][101][101];
int field[101][101];
int lineEmpNum[101];

void RotateBlock(){
    for(int k=0;k<3;k++){
        int newBlock[101][101];
        memset(newBlock,0,sizeof(newBlock));
        for(int j=0;j<blW;j++)for(int i=0;i<blH;i++)
            newBlock[j][blH-1-i]=block[k][i][j];
        for(int i=0;i<blH;i++)for(int j=0;j<blW;j++)
            block[k+1][i][j]=newBlock[i][j];
        swap(blW,blH);
    }
    swap(blW,blH);
}

int main(){
    cin>>N;
    while(N--){
        cin>>blH>>blW;
        for(int i=0;i<blH;i++){
            for(int j=0;j<blW;j++){
                char ch;
                cin>>ch;
                if(ch=='#')block[0][i][j]=1;
                else block[0][i][j]=0;
            }
        }
        blH=max(blH,blW);
        blW=max(blW,blH);
        cin>>bdH>>bdW;
        for(int i=0;i<bdH;i++){
            lineEmpNum[i]=0;
            for(int j=0;j<bdW;j++){
                char ch;
                cin>>ch;
                if(ch=='#')field[i][j]=1;
                else{
                    lineEmpNum[i]++;
                    field[i][j]=0;
                }
            }
        }
        // ÂuÂÂÂbÂNÂÃ°ÂÃ±Â]ÂÂ³ÂÂ¹ÂÃÂÃÂSÂÃªÂÂÂÃ°ÂÂÂÂ·
        // ÂuÂÂÂbÂNÂÃÂEÂÂºÂÃÂÃÂWÂÂªÂ{Â[ÂhÂÃ£ÂÃÂÃÂÃÂÃÂWÂÃÂÃªÂvÂÂ·ÂÃ©ÂÂ©ÂH
        // ÂÃ±Â]
        RotateBlock();
        int res=0;
        for(int k=0;k<4;k++){
            for(int i=0;i<bdH+blH-1;i++){
                for(int j=0;j<bdW+blW-1;j++){
                    int cnt=0;
                    // ÂuÂÂÂbÂNÂÂªÂÃÂÃÂoÂÃ©ÂÃ ÂÂµÂÂ­ÂÃÂdÂÃÂÃ¨Â`ÂFÂbÂN
                    bool isSetable=true;
                    for(int l=0;l<blH;l++){
                        int bdy=-blH+l+1+i;
                        int a=0;
                        for(int m=0;m<blW;m++){
                            int bdx=-blW+m+1+j;
                            if(bdx>=0&&bdy>=0&&bdx<bdW&&bdy<bdH){
                                if(block[k][l][m]&&field[bdy][bdx])isSetable=false;
                                else{
                                    // ÂÂ¡ÂÃ°ÂÂÂÃÂÃ©
                                    if(block[k][l][m])a++;
                                }
                            }
                            else{
                                if(block[k][l][m])isSetable=false;
                            }
                            if(!isSetable)break;
                        }
                        // bdyÂÃÂsÂÂªÂÂÂÃÂÃªÂÃcntÂÃ°ÂCÂÂÂNÂÂÂÂÂÂÂg
                        if(bdy>=0&&bdy<bdH&&a==lineEmpNum[bdy])cnt++;
                        if(!isSetable)break;
                    }
                    if(isSetable)res=max(res,cnt);
                }
            }
            swap(blH,blW);
        }
        if(res==0)cout<<-1<<endl;
        else cout<<res<<endl;
    }

    return 0;
}

Compiler output:
a.cc: In function 'void RotateBlock()':
a.cc:17:9: error: 'memset' was not declared in this scope
   17 |         memset(newBlock,0,sizeof(newBlock));
      |         ^~~~~~
a.cc:4:1: note: 'memset' is defined in header '<cstring>'; this is probably fixable by adding '#include <cstring>'
    3 | #include <vector>
  +++ |+#include <cstring>
    4 |