#include <bits/stdc++.h>

using namespace std;

int main()
{
    long long t;
    cin>>t;

    for (long long z=0;z<t;z++)
    {
        long long n,m;
        cin>>n>>m;

        long long matrica1[n+10][m+10];
        long long matrica2[n+10][m+10];

        for (long long i=1;i<=n;i++)
        {
            for (long long j=1;j<=m;j++) cin>>matrica1[i][j];
        }

        for (long long i=1;i<=n;i++)
        {
            for (long long j=1;j<=m;j++) cin>>matrica2[i][j];
        }

        long long sum=0;

        for (long long i=1;i<=n;i++)
        {
            for (long long j=1;j<=m;j++) sum+=matrica1[i][j];
        }

        if (sum%2==1) cout<<"NE"<<endl;
        else
        {
            cout<<"DA"<<endl;

            for (long long i=1;i<=n;i++)
            {
                for (long long j=1;j<=m;j++) cout<<matrica1[i][j]<<" ";
                cout<<endl;
            }
        }
    }
}