I have used Brute-Force but i am not getting right answer, can anyone please tell me whats wrong…??

LINK: https://pastebin.com/Z9LQneSF

#include<bits/stdc++.h>

#define ll long long int

using namespace std;

int main(){

ll t; cin>>t;

while(t–){

int n,m; cin>>n>>m;

int a[n][m],b[n][m];

string s;

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

cin>>s;

for(int j=0;j<m;j++){

a[i][j] = (s[j] - ‘0’);

}

}

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

cin>>s;

for(int j=0;j<m;j++){

b[i][j] = (s[j] - ‘0’);

}

}

int dr = -n, dc = -m;

int ans = INT_MAX, r , c, cmp, tp;

while(dr < n){

dc = -m;

while(dc < m){

tp = 0;

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

for(int j=0;j<m;j++){

r = i + dr;

c = j + dc;

if(r < 0 || r > n || c < 0 || c > m){

cmp = 0;

}

else{

cmp = b[r][c];

}

if(cmp != a[i][j]){

tp++;

}

}

}

ans = min(ans,tp);

dc++;

}

dr++;

}

cout<<"ANS "<<ans<<endl;

}

return 0;

}