intread(){ char c = getchar(); while(c > '9' || c < '0') c = getchar(); int res = 0; while(c <= '9' && c >= '0') { res = res * 10 + (c ^ 48); c = getchar(); } return res; }
constexprint C = 1e9 + 151, MOD = 1e9 + 7;
signedmain(){ int t = read(); while(t--) { int n = read(), m = read(); bool ok = 1; longlong prv; for(int i = 0; i < n; i++) { longlong cur = 0, xcur = 0; for(int j = 0, w; j < m; j++) { w = read(); if(j) cur = (cur * C + w) % MOD; if(j < m - 1) xcur = (xcur * C + w) % MOD; } if(i) ok &= prv == cur; prv = xcur; } puts(ok ? "Yes" : "No"); } }