#include using namespace std; int main(){ ios::sync_with_stdio(false); cin.tie(nullptr); int T; cin>>T; while(T--){ int H,W; cin>>H>>W; if(H>=3||W>=3){ vector>ans(H,vector(W)); int tH=(H%3==1)*2,tW=(W%3==1)*2; for(int i=0;i>ans(H,vector(W)); int t=i; for(int j=0;j0&&ans[j-1][k]==ans[j][k])cnt+=1; if(j0&&ans[j][k-1]==ans[j][k])cnt+=1; if(k