#include <bits/stdc++.h>
using namespace std;
struct Edge {
int to;
int rev;
int cap;
};
class MaxFlow {
public:
int N;
vector<vector<Edge>> graph;
vector<int> level;
vector<int> ptr;
MaxFlow(int N_) : N(N_), graph(N, vector<Edge>()), level(N, -1), ptr(N, 0) {}
void add_edge(int from, int to, int cap){
Edge a = {to, (int)graph[to].size(), cap};
Edge b = {from, (int)(graph[from].size()), 0};
graph[from].push_back(a);
graph[to].push_back(b);
}
bool bfs(int s, int t){
fill(level.begin(), level.end(), -1);
queue<int> q; q.push(s);
level[s] = 0;
while(!q.empty()){
int v = q.front(); q.pop();
for(auto &e: graph[v]){
if(e.cap >0 && level[e.to]==-1){
level[e.to]=level[v]+1;
q.push(e.to);
}
}
}
return level[t]!=-1;
}
int dfs(int v, int t, int pushed){
if(v == t) return pushed;
for(int &cid=ptr[v]; cid < graph[v].size(); cid++){
Edge &e = graph[v][cid];
if(e.cap >0 && level[e.to]==level[v]+1){
int tr = dfs(e.to, t, min(pushed, e.cap));
if(tr >0){
graph[v][cid].cap -= tr;
graph[e.to][e.rev].cap += tr;
return tr;
}
}
}
return 0;
}
int max_flow(int s, int t){
int flow=0;
while(bfs(s, t)){
fill(ptr.begin(), ptr.end(), 0);
while(int pushed = dfs(s, t, INT32_MAX)){
flow += pushed;
}
}
return flow;
}
};
int main(){
ios::sync_with_stdio(false);
cin.tie(0);
int t;
cin >> t;
while(t--){
int n, m;
cin >> n >> m;
// Read n x m numbers
vector<vector<long long>> scaled_x(n, vector<long long>(m, 0));
for(int i=0; i<n; ++i){
for(int j=0; j<m; ++j){
string s;
cin >> s;
// Convert to integer scaled by 1000
size_t dot = s.find('.');
long long whole = 0, frac =0;
if(dot == string::npos){
whole = stoll(s);
}
else{
whole = stoll(s.substr(0, dot));
string frac_s = s.substr(dot+1);
while(frac_s.size() <3) frac_s += '0';
frac = stoll(frac_s.substr(0,3));
}
if(whole <0 && frac >0){
scaled_x[i][j] = whole * 1000 - frac;
}
else{
scaled_x[i][j] = whole * 1000 + frac;
}
}
}
// Compute floor and d
vector<vector<long long>> floor_x(n, vector<long long>(m, 0));
vector<vector<long long>> d(n, vector<long long>(m, 0));
for(int i=0; i<n; ++i){
for(int j=0; j<m; ++j){
if(scaled_x[i][j] >=0){
floor_x[i][j] = scaled_x[i][j] / 1000;
d[i][j] = scaled_x[i][j] % 1000;
}
else{
floor_x[i][j] = ceil((double)scaled_x[i][j] / 1000.0);
d[i][j] = scaled_x[i][j] - floor_x[i][j]*1000;
}
}
}
// Compute row and column sums
vector<long long> row_sum_scaled(n, 0);
vector<long long> col_sum_scaled(m, 0);
for(int i=0; i<n; ++i){
for(int j=0; j<m; ++j){
row_sum_scaled[i] += scaled_x[i][j];
col_sum_scaled[j] += scaled_x[i][j];
}
}
bool possible=true;
// Check if all row and column sums are multiples of 1000
for(int i=0; i<n && possible; ++i){
if(row_sum_scaled[i] % 1000 !=0){
possible=false;
}
}
for(int j=0; j<m && possible; ++j){
if(col_sum_scaled[j] % 1000 !=0){
possible=false;
}
}
if(!possible){
cout << "NO\n";
continue;
}
// Compute r[i] and c[j]
vector<long long> r(n, 0);
vector<long long> c(m, 0);
for(int i=0; i<n; ++i){
long long floor_sum =0;
for(int j=0; j<m; ++j){
floor_sum += floor_x[i][j];
}
r[i] = (row_sum_scaled[i]/1000) - floor_sum;
}
for(int j=0; j<m; ++j){
long long floor_sum =0;
for(int i=0; i<n; ++i){
floor_sum += floor_x[i][j];
}
c[j] = (col_sum_scaled[j]/1000) - floor_sum;
}
// Check if r[i] and c[j] are feasible
// i.e., r[i] <= number of cells with d[i][j]>0 in row i
bool feasible=true;
for(int i=0; i<n && feasible; ++i){
int cnt=0;
for(int j=0; j<m; ++j){
if(d[i][j] >0){
cnt++;
}
}
if(r[i] <0 || r[i] > cnt){
feasible=false;
}
}
for(int j=0; j<m && feasible; ++j){
int cnt=0;
for(int i=0; i<n; ++i){
if(d[i][j] >0){
cnt++;
}
}
if(c[j] <0 || c[j] > cnt){
feasible=false;
}
}
// Check sum r[i] == sum c[j]
long long total_r=0, total_c=0;
for(auto val: r) total_r += val;
for(auto val: c) total_c += val;
if(total_r != total_c){
feasible=false;
}
if(!feasible){
cout << "NO\n";
continue;
}
// Build flow network
int S=0, T=n+m+1;
MaxFlow mf(T+1);
for(int i=0; i<n; ++i){
mf.add_edge(S, 1+i, r[i]);
}
for(int j=0; j<m; ++j){
mf.add_edge(1+n+j, T, c[j]);
}
for(int i=0; i<n; ++i){
for(int j=0; j<m; ++j){
if(d[i][j] >0){
mf.add_edge(1+i, 1+n+j, 1);
}
}
}
int flow = mf.max_flow(S, T);
if(flow != total_r){
cout << "NO\n";
continue;
}
// Reconstruct y matrix
vector<vector<int>> y(n, vector<int>(m, 0));
for(int i=0; i<n; ++i){
for(auto &e: mf.graph[1+i]){
if(e.to >=1+n && e.to <=n+m && e.cap ==0){
int j = e.to - (1+n);
y[i][j] =1;
}
}
}
// Now, assign y[j][k] =0 for cells with d[i][j] =0
// According to the problem and sample, it's allowed to set y=1 for these cells,
// but it doesn't affect the row and column sums.
// To align with the sample, we can set them to 0.
// If needed, they can be set to 1, but it's optional.
// Here, we'll set them to 0.
for(int i=0; i<n; ++i){
for(int j=0; j<m; ++j){
if(d[i][j] ==0){
y[i][j] =0;
}
}
}
// Now, verify that the sum constraints are met
bool valid=true;
// Check rows
for(int i=0; i<n && valid; ++i){
long long sum =0;
for(int j=0; j<m; ++j){
sum += (floor_x[i][j] + y[i][j]);
}
if(sum != (row_sum_scaled[i]/1000)){
valid=false;
}
}
// Check columns
for(int j=0; j<m && valid; ++j){
long long sum =0;
for(int i=0; i<n; ++i){
sum += (floor_x[i][j] + y[i][j]);
}
if(sum != (col_sum_scaled[j]/1000)){
valid=false;
}
}
if(!valid){
cout << "NO\n";
continue;
}
// Output
cout << "YES\n";
for(int i=0; i<n; ++i){
for(int j=0; j<m; ++j){
cout << y[i][j];
if(j != m-1) cout << ' ';
}
cout << '\n';
}
}
}