/*starting with the name of almighty ALLAH*/
/*solved by RAKIB JOY*/
// Practice is the only shortcut to improve
#include<bits/stdc++.h>
#define ll long long int
#define pb push_back
#define vc vector
#define vi vc<int>
#define vl vc<ll>
#define dbg(x) cout<<x<<endl;
#define mp(x,y) make_pair(x,y)
#define yes dbg("YES")
#define no dbg("NO")
#define tst int t;cin>>t;while(t--)
#define srt(v) sort(v.begin(),v.end());
#define rsrt(v) sort(v.rbegin(),v.rend());
#define rj ios::sync_with_stdio(false);cin.tie(0);
#define rvs(v) reverse(v.begin(),v.end());
#define F first
#define S second
#define mod 1000000007
#define gcd(a,b) __gcd(a,b)
#define lcm(a,b) (a*b)/gcd(a,b)
#define PI 2*acos(0.0)
#define pii pair<int,int>
#define fr(i,a,b) for(ll i=a;i<=b;i++)
#define coutv(v) for(auto it:v)cout<<it<<' ';cout<<endl;
#define cinv(v) for(auto &it:v)cin>>it;
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define ld long double
using namespace std;
/*#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
template<typename T> using ordered_set =tree<T, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>;
*/
//sieve bool b[1000005];void primenire(){int i, j;b[0]=true;b[1]=true;for(i=4; i<=1000000; i+=2){b[i]=true;}for(i=3; i<=1001; i+=2){if(!b[i]){for(j=i*i; j<=1000001; j+=2*i){b[j]=true;}}}}
// power ll power(ll a,ll b){if(b==0)return 1LL;if(b&1)return a*power(a,b-1);else{ll x=power(a,b/2);return x*x;}}
//bigmod long long int m(long long int a,long long int b,long long int c){if(b==0)return 1;if(b%2==0){long long int  tmp=m(a,b/2,c);return ((tmp%c)*(tmp%c))%c;}elsereturn ((a%c)*(m(a,b-1,c)%c))%c;}
//MaxSubarraySum ll mss(vector<ll>v){ll mx=v[0];ll sz=v.size();for(int i=1;i<=sz;i++){ll t=v[i]+v[i-1];if(t>=v[i]) v[i]=t;mx=max(mx,v[i]*1LL);}return mx;}
//combination ll com[1001][1001];void combination(){com[1][1]=1;com[1][0]=1;for(ll i=2; i<=1000; i++){com[i][0]=1;for(ll j=1; j<=i; j++){com[i][j]=com[i-1][j]+com[i-1][j-1];}}}
///--------------Graph Moves--------------------------------------
///const int fx[] = {+1,-1,+0,+0};
///const int fy[] = {+0,+0,+1,-1};
///const int fx[] = {+0,+0,+1,-1,-1,+1,-1,+1}; ///King's move
///const int fy[] = {-1,+1,+0,+0,+1,+1,-1,-1}; ///king's Move
///const int fx[] = {-2,-2,-1,-1,+1,+1,+2,+2}; ///knight's move
///const int fy[] = {-1,+1,-2,+2,-2,+2,-1,+1}; ///knight's move
///---------------------------------------------------------------
ll v[105][105];
bool vis[105][105];
void solve()
{
    memset(v,0,sizeof v);
    memset(vis,false,sizeof vis);
    ll a,b;
    cin>>a>>b;
    fr(i,1,a) fr(j,1,b) cin>>v[i][j];

    for(ll k=4; k>=1; k--)
    {

        fr(i,1,a)
        {
            fr(j,1,b)
            {
                if(vis[i][j])
                    continue;
                ll p=0;
                if(v[i][j]==v[i+1][j])
                    p++;
                if(v[i][j]==v[i-1][j])
                    p++;
                if(v[i][j]==v[i][j+1])
                    p++;
                if(v[i][j]==v[i][j-1])
                    p++;

                if(p>=k)
                {
                    v[i][j]++;
                    vis[i][j]=1;

                }
            }
        }
    }

    fr(i,1,a)
    {
        fr(j,1,b) cout<<v[i][j]<<' ';
        cout<<endl;
    }
}
int main()
{
    rj
    tst
    solve();
    return 0;
}


/*starting with the name of almighty ALLAH*/
/*solved by RAKIB JOY*/
// Practice is the only shortcut to improve
#include<bits/stdc++.h>
#define ll long long int
#define pb push_back
#define vc vector
#define vi vc<int>
#define vl vc<ll>
#define dbg(x) cout<<x<<endl;
#define mp(x,y) make_pair(x,y)
#define yes dbg("YES")
#define no dbg("NO")
#define tst int t;cin>>t;while(t--)
#define srt(v) sort(v.begin(),v.end());
#define rsrt(v) sort(v.rbegin(),v.rend());
#define rj ios::sync_with_stdio(false);cin.tie(0);
#define rvs(v) reverse(v.begin(),v.end());
#define F first
#define S second
#define mod 1000000007
#define gcd(a,b) __gcd(a,b)
#define lcm(a,b) (a*b)/gcd(a,b)
#define PI 2*acos(0.0)
#define pii pair<int,int>
#define fr(i,a,b) for(ll i=a;i<=b;i++)
#define coutv(v) for(auto it:v)cout<<it<<' ';cout<<endl;
#define cinv(v) for(auto &it:v)cin>>it;
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define ld long double
using namespace std;
/*#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
template<typename T> using ordered_set =tree<T, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>;
*/
//sieve bool b[1000005];void primenire(){int i, j;b[0]=true;b[1]=true;for(i=4; i<=1000000; i+=2){b[i]=true;}for(i=3; i<=1001; i+=2){if(!b[i]){for(j=i*i; j<=1000001; j+=2*i){b[j]=true;}}}}
// power ll power(ll a,ll b){if(b==0)return 1LL;if(b&1)return a*power(a,b-1);else{ll x=power(a,b/2);return x*x;}}
//bigmod long long int m(long long int a,long long int b,long long int c){if(b==0)return 1;if(b%2==0){long long int  tmp=m(a,b/2,c);return ((tmp%c)*(tmp%c))%c;}elsereturn ((a%c)*(m(a,b-1,c)%c))%c;}
//MaxSubarraySum ll mss(vector<ll>v){ll mx=v[0];ll sz=v.size();for(int i=1;i<=sz;i++){ll t=v[i]+v[i-1];if(t>=v[i]) v[i]=t;mx=max(mx,v[i]*1LL);}return mx;}
//combination ll com[1001][1001];void combination(){com[1][1]=1;com[1][0]=1;for(ll i=2; i<=1000; i++){com[i][0]=1;for(ll j=1; j<=i; j++){com[i][j]=com[i-1][j]+com[i-1][j-1];}}}
///--------------Graph Moves--------------------------------------
///const int fx[] = {+1,-1,+0,+0};
///const int fy[] = {+0,+0,+1,-1};
///const int fx[] = {+0,+0,+1,-1,-1,+1,-1,+1}; ///King's move
///const int fy[] = {-1,+1,+0,+0,+1,+1,-1,-1}; ///king's Move
///const int fx[] = {-2,-2,-1,-1,+1,+1,+2,+2}; ///knight's move
///const int fy[] = {-1,+1,-2,+2,-2,+2,-1,+1}; ///knight's move
///---------------------------------------------------------------
ll v[105][105];
bool vis[105][105];
void solve()
{
    memset(v,0,sizeof v);
    memset(vis,false,sizeof vis);
    ll a,b;
    cin>>a>>b;
    fr(i,1,a) fr(j,1,b) cin>>v[i][j];
    fr(k,1,100)
    {

        fr(i,1,a)
        {
            fr(j,1,b)
            {
                if(vis[i][j])
                    continue;
                if(v[i+1][j]==v[i][j]||v[i-1][j]==v[i][j]||v[i][j+1]==v[i][j]||v[i][j-1]==v[i][j])
                {
                   if(v[i+1][j]==v[i][j]+1||v[i-1][j]==v[i][j]+1||v[i][j+1]==v[i][j]+1||v[i][j-1]==v[i][j]+1) continue;
                    v[i][j]++;
                    vis[i][j]=1;

                }
            }
        }
    }
    fr(i,1,a)
    {
        fr(j,1,b) cout<<v[i][j]<<' ';
        cout<<endl;
    }
}
int main()
{
    rj
    tst
    solve();
    return 0;
}


/*starting with the name of almighty ALLAH*/
/*solved by RAKIB JOY*/
// Practice is the only shortcut to improve
#include<bits/stdc++.h>
#define ll long long int
#define pb push_back
#define vc vector
#define vi vc<int>
#define vl vc<ll>
#define dbg(x) cout<<x<<endl;
#define mp(x,y) make_pair(x,y)
#define yes dbg("YES")
#define no dbg("NO")
#define tst int t;cin>>t;while(t--)
#define srt(v) sort(v.begin(),v.end());
#define rsrt(v) sort(v.rbegin(),v.rend());
#define rj ios::sync_with_stdio(false);cin.tie(0);
#define rvs(v) reverse(v.begin(),v.end());
#define F first
#define S second
#define mod 1000000007
#define gcd(a,b) __gcd(a,b)
#define lcm(a,b) (a*b)/gcd(a,b)
#define PI 2*acos(0.0)
#define pii pair<int,int>
#define fr(i,a,b) for(ll i=a;i<=b;i++)
#define coutv(v) for(auto it:v)cout<<it<<' ';cout<<endl;
#define cinv(v) for(auto &it:v)cin>>it;
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define ld long double
using namespace std;
/*#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
template<typename T> using ordered_set =tree<T, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>;
*/
//sieve bool b[1000005];void primenire(){int i, j;b[0]=true;b[1]=true;for(i=4; i<=1000000; i+=2){b[i]=true;}for(i=3; i<=1001; i+=2){if(!b[i]){for(j=i*i; j<=1000001; j+=2*i){b[j]=true;}}}}
// power ll power(ll a,ll b){if(b==0)return 1LL;if(b&1)return a*power(a,b-1);else{ll x=power(a,b/2);return x*x;}}
//bigmod long long int m(long long int a,long long int b,long long int c){if(b==0)return 1;if(b%2==0){long long int  tmp=m(a,b/2,c);return ((tmp%c)*(tmp%c))%c;}elsereturn ((a%c)*(m(a,b-1,c)%c))%c;}
//MaxSubarraySum ll mss(vector<ll>v){ll mx=v[0];ll sz=v.size();for(int i=1;i<=sz;i++){ll t=v[i]+v[i-1];if(t>=v[i]) v[i]=t;mx=max(mx,v[i]*1LL);}return mx;}
//combination ll com[1001][1001];void combination(){com[1][1]=1;com[1][0]=1;for(ll i=2; i<=1000; i++){com[i][0]=1;for(ll j=1; j<=i; j++){com[i][j]=com[i-1][j]+com[i-1][j-1];}}}
///--------------Graph Moves--------------------------------------
///const int fx[] = {+1,-1,+0,+0};
///const int fy[] = {+0,+0,+1,-1};
///const int fx[] = {+0,+0,+1,-1,-1,+1,-1,+1}; ///King's move
///const int fy[] = {-1,+1,+0,+0,+1,+1,-1,-1}; ///king's Move
///const int fx[] = {-2,-2,-1,-1,+1,+1,+2,+2}; ///knight's move
///const int fy[] = {-1,+1,-2,+2,-2,+2,-1,+1}; ///knight's move
///---------------------------------------------------------------
ll v[105][105];
bool vis[105][105];
void solve()
{
    memset(v,0,sizeof v);
    memset(vis,false,sizeof vis);
    ll a,b;
    cin>>a>>b;
    fr(i,1,a) fr(j,1,b) cin>>v[i][j];

       fr(k,1,a*b)
        fr(i,1,a)
        {
            fr(j,1,b)
            {
                if(vis[i][j])
                    continue;
                if(v[i+1][j]==v[i][j]||v[i-1][j]==v[i][j]||v[i][j+1]==v[i][j]||v[i][j-1]==v[i][j])
                {

                    v[i][j]++;
                    vis[i][j]=1;

                }
            }
        }

    fr(i,1,a)
    {
        fr(j,1,b) cout<<v[i][j]<<' ';
        cout<<endl;
    }
}
int main()
{
    rj
    tst
    solve();
    return 0;
}


/*starting with the name of almighty ALLAH*/
/*solved by RAKIB JOY*/
// Practice is the only shortcut to improve
#include<bits/stdc++.h>
#define ll long long int
#define pb push_back
#define vc vector
#define vi vc<int>
#define vl vc<ll>
#define dbg(x) cout<<x<<endl;
#define mp(x,y) make_pair(x,y)
#define yes dbg("YES")
#define no dbg("NO")
#define tst int t;cin>>t;while(t--)
#define srt(v) sort(v.begin(),v.end());
#define rsrt(v) sort(v.rbegin(),v.rend());
#define rj ios::sync_with_stdio(false);cin.tie(0);
#define rvs(v) reverse(v.begin(),v.end());
#define F first
#define S second
#define mod 1000000007
#define gcd(a,b) __gcd(a,b)
#define lcm(a,b) (a*b)/gcd(a,b)
#define PI 2*acos(0.0)
#define pii pair<int,int>
#define fr(i,a,b) for(ll i=a;i<=b;i++)
#define coutv(v) for(auto it:v)cout<<it<<' ';cout<<endl;
#define cinv(v) for(auto &it:v)cin>>it;
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define ld long double
using namespace std;
/*#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
template<typename T> using ordered_set =tree<T, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>;
*/
//sieve bool b[1000005];void primenire(){int i, j;b[0]=true;b[1]=true;for(i=4; i<=1000000; i+=2){b[i]=true;}for(i=3; i<=1001; i+=2){if(!b[i]){for(j=i*i; j<=1000001; j+=2*i){b[j]=true;}}}}
// power ll power(ll a,ll b){if(b==0)return 1LL;if(b&1)return a*power(a,b-1);else{ll x=power(a,b/2);return x*x;}}
//bigmod long long int m(long long int a,long long int b,long long int c){if(b==0)return 1;if(b%2==0){long long int  tmp=m(a,b/2,c);return ((tmp%c)*(tmp%c))%c;}elsereturn ((a%c)*(m(a,b-1,c)%c))%c;}
//MaxSubarraySum ll mss(vector<ll>v){ll mx=v[0];ll sz=v.size();for(int i=1;i<=sz;i++){ll t=v[i]+v[i-1];if(t>=v[i]) v[i]=t;mx=max(mx,v[i]*1LL);}return mx;}
//combination ll com[1001][1001];void combination(){com[1][1]=1;com[1][0]=1;for(ll i=2; i<=1000; i++){com[i][0]=1;for(ll j=1; j<=i; j++){com[i][j]=com[i-1][j]+com[i-1][j-1];}}}
///--------------Graph Moves--------------------------------------
///const int fx[] = {+1,-1,+0,+0};
///const int fy[] = {+0,+0,+1,-1};
///const int fx[] = {+0,+0,+1,-1,-1,+1,-1,+1}; ///King's move
///const int fy[] = {-1,+1,+0,+0,+1,+1,-1,-1}; ///king's Move
///const int fx[] = {-2,-2,-1,-1,+1,+1,+2,+2}; ///knight's move
///const int fy[] = {-1,+1,-2,+2,-2,+2,-1,+1}; ///knight's move
///---------------------------------------------------------------
ll v[105][105];
bool vis[105][105];
void solve()
{
    memset(v,0,sizeof v);
    memset(vis,0,sizeof vis);
    ll a,b;
    cin>>a>>b;
    fr(i,1,a) fr(j,1,b) cin>>v[i][j];
    fr(i,1,a)
    {
        fr(j,1,b)
        {
            if(vis[i][j])
                continue;
            if(v[i+1][j]==v[i][j]||v[i-1][j]==v[i][j]||v[i][j+1]==v[i][j]||v[i][j-1]==v[i][j])
            {
                v[i][j]++;
                vis[i][j]=1;
                vis[i+1][j]=1;
                vis[i-1][j]=1;
                vis[i][j+1]=1;
                vis[i][j-1]=1;
            }
        }
    }
    fr(i,1,a)
    {
       fr(j,1,b) cout<<v[i][j]<<' ';
       cout<<endl;
    }
}
int main()
{
    rj
    tst
    solve();
    return 0;
}


/*starting with the name of almighty ALLAH*/
/*solved by RAKIB JOY*/
// Practice is the only shortcut to improve
#include<bits/stdc++.h>
#define ll long long int
#define pb push_back
#define vc vector
#define vi vc<int>
#define vl vc<ll>
#define dbg(x) cout<<x<<endl;
#define mp(x,y) make_pair(x,y)
#define yes dbg("YES")
#define no dbg("NO")
#define tst int t;cin>>t;while(t--)
#define srt(v) sort(v.begin(),v.end());
#define rsrt(v) sort(v.rbegin(),v.rend());
#define rj ios::sync_with_stdio(false);cin.tie(0);
#define rvs(v) reverse(v.begin(),v.end());
#define F first
#define S second
#define mod 1000000007
#define gcd(a,b) __gcd(a,b)
#define lcm(a,b) (a*b)/gcd(a,b)
#define PI 2*acos(0.0)
#define pii pair<int,int>
#define fr(i,a,b) for(ll i=a;i<=b;i++)
#define coutv(v) for(auto it:v)cout<<it<<' ';cout<<endl;
#define cinv(v) for(auto &it:v)cin>>it;
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define ld long double
using namespace std;
/*#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
template<typename T> using ordered_set =tree<T, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>;
*/
//sieve bool b[1000005];void primenire(){int i, j;b[0]=true;b[1]=true;for(i=4; i<=1000000; i+=2){b[i]=true;}for(i=3; i<=1001; i+=2){if(!b[i]){for(j=i*i; j<=1000001; j+=2*i){b[j]=true;}}}}
// power ll power(ll a,ll b){if(b==0)return 1LL;if(b&1)return a*power(a,b-1);else{ll x=power(a,b/2);return x*x;}}
//bigmod long long int m(long long int a,long long int b,long long int c){if(b==0)return 1;if(b%2==0){long long int  tmp=m(a,b/2,c);return ((tmp%c)*(tmp%c))%c;}elsereturn ((a%c)*(m(a,b-1,c)%c))%c;}
//MaxSubarraySum ll mss(vector<ll>v){ll mx=v[0];ll sz=v.size();for(int i=1;i<=sz;i++){ll t=v[i]+v[i-1];if(t>=v[i]) v[i]=t;mx=max(mx,v[i]*1LL);}return mx;}
//combination ll com[1001][1001];void combination(){com[1][1]=1;com[1][0]=1;for(ll i=2; i<=1000; i++){com[i][0]=1;for(ll j=1; j<=i; j++){com[i][j]=com[i-1][j]+com[i-1][j-1];}}}
///--------------Graph Moves--------------------------------------
///const int fx[] = {+1,-1,+0,+0};
///const int fy[] = {+0,+0,+1,-1};
///const int fx[] = {+0,+0,+1,-1,-1,+1,-1,+1}; ///King's move
///const int fy[] = {-1,+1,+0,+0,+1,+1,-1,-1}; ///king's Move
///const int fx[] = {-2,-2,-1,-1,+1,+1,+2,+2}; ///knight's move
///const int fy[] = {-1,+1,-2,+2,-2,+2,-1,+1}; ///knight's move
///---------------------------------------------------------------
ll v[105][105];
bool vis[105][105];
void solve()
{
    memset(v,0,sizeof v);
    memset(vis,false,sizeof vis);
    ll a,b;
    cin>>a>>b;
    fr(i,1,a) fr(j,1,b) cin>>v[i][j];
    fr(k,1,100)
    {

        fr(i,1,a)
        {
            fr(j,1,b)
            {
                if(vis[i][j])
                    continue;
                if(v[i+1][j]==v[i][j]||v[i-1][j]==v[i][j]||v[i][j+1]==v[i][j]||v[i][j-1]==v[i][j])
                {
                    v[i][j]++;
                    vis[i][j]=1;
                    if(v[i+1][j]+1==v[i][j])
                        vis[i+1][j]=1;
                    if(v[i][j+1]+1==v[i][j])
                        vis[i][j+1]=1;

                }
            }
        }
    }
    fr(i,1,a)
    {
        fr(j,1,b) cout<<v[i][j]<<' ';
        cout<<endl;
    }
}
int main()
{
    rj
    tst
    solve();
    return 0;
}


/*starting with the name of almighty ALLAH*/
/*solved by RAKIB JOY*/
// Practice is the only shortcut to improve
#include<bits/stdc++.h>
#define ll long long int
#define pb push_back
#define vc vector
#define vi vc<int>
#define vl vc<ll>
#define dbg(x) cout<<x<<endl;
#define mp(x,y) make_pair(x,y)
#define yes dbg("YES")
#define no dbg("NO")
#define tst int t;cin>>t;while(t--)
#define srt(v) sort(v.begin(),v.end());
#define rsrt(v) sort(v.rbegin(),v.rend());
#define rj ios::sync_with_stdio(false);cin.tie(0);
#define rvs(v) reverse(v.begin(),v.end());
#define F first
#define S second
#define mod 1000000007
#define gcd(a,b) __gcd(a,b)
#define lcm(a,b) (a*b)/gcd(a,b)
#define PI 2*acos(0.0)
#define pii pair<int,int>
#define fr(i,a,b) for(ll i=a;i<=b;i++)
#define coutv(v) for(auto it:v)cout<<it<<' ';cout<<endl;
#define cinv(v) for(auto &it:v)cin>>it;
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define ld long double
using namespace std;
/*#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
template<typename T> using ordered_set =tree<T, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>;
*/
//sieve bool b[1000005];void primenire(){int i, j;b[0]=true;b[1]=true;for(i=4; i<=1000000; i+=2){b[i]=true;}for(i=3; i<=1001; i+=2){if(!b[i]){for(j=i*i; j<=1000001; j+=2*i){b[j]=true;}}}}
// power ll power(ll a,ll b){if(b==0)return 1LL;if(b&1)return a*power(a,b-1);else{ll x=power(a,b/2);return x*x;}}
//bigmod long long int m(long long int a,long long int b,long long int c){if(b==0)return 1;if(b%2==0){long long int  tmp=m(a,b/2,c);return ((tmp%c)*(tmp%c))%c;}elsereturn ((a%c)*(m(a,b-1,c)%c))%c;}
//MaxSubarraySum ll mss(vector<ll>v){ll mx=v[0];ll sz=v.size();for(int i=1;i<=sz;i++){ll t=v[i]+v[i-1];if(t>=v[i]) v[i]=t;mx=max(mx,v[i]*1LL);}return mx;}
//combination ll com[1001][1001];void combination(){com[1][1]=1;com[1][0]=1;for(ll i=2; i<=1000; i++){com[i][0]=1;for(ll j=1; j<=i; j++){com[i][j]=com[i-1][j]+com[i-1][j-1];}}}
///--------------Graph Moves--------------------------------------
///const int fx[] = {+1,-1,+0,+0};
///const int fy[] = {+0,+0,+1,-1};
///const int fx[] = {+0,+0,+1,-1,-1,+1,-1,+1}; ///King's move
///const int fy[] = {-1,+1,+0,+0,+1,+1,-1,-1}; ///king's Move
///const int fx[] = {-2,-2,-1,-1,+1,+1,+2,+2}; ///knight's move
///const int fy[] = {-1,+1,-2,+2,-2,+2,-1,+1}; ///knight's move
///---------------------------------------------------------------
ll v[105][105];
bool vis[105][105];
void solve()
{
    memset(v,0,sizeof v);
    memset(vis,false,sizeof vis);
    ll a,b;
    cin>>a>>b;
    fr(i,1,a) fr(j,1,b) cin>>v[i][j];

    for(ll k=4; k>=1; k--)
    {

        fr(i,1,a)
        {
            fr(j,1,b)
            {
               if(v[i][j]%2!=(i+j)%2) v[i][j]++;
            }
        }
    }

    fr(i,1,a)
    {
        fr(j,1,b) cout<<v[i][j]<<' ';
        cout<<endl;
    }
}
int main()
{
    rj
    tst
    solve();
    return 0;
}


/*starting with the name of almighty ALLAH*/
/*solved by RAKIB JOY*/
// Practice is the only shortcut to improve
#include<bits/stdc++.h>
#define ll long long int
#define pb push_back
#define vc vector
#define vi vc<int>
#define vl vc<ll>
#define dbg(x) cout<<x<<endl;
#define mp(x,y) make_pair(x,y)
#define yes dbg("YES")
#define no dbg("NO")
#define tst int t;cin>>t;while(t--)
#define srt(v) sort(v.begin(),v.end());
#define rsrt(v) sort(v.rbegin(),v.rend());
#define rj ios::sync_with_stdio(false);cin.tie(0);
#define rvs(v) reverse(v.begin(),v.end());
#define F first
#define S second
#define mod 1000000007
#define gcd(a,b) __gcd(a,b)
#define lcm(a,b) (a*b)/gcd(a,b)
#define PI 2*acos(0.0)
#define pii pair<int,int>
#define fr(i,a,b) for(ll i=a;i<=b;i++)
#define coutv(v) for(auto it:v)cout<<it<<' ';cout<<endl;
#define cinv(v) for(auto &it:v)cin>>it;
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define ld long double
using namespace std;
/*#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
template<typename T> using ordered_set =tree<T, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>;
*/
//sieve bool b[1000005];void primenire(){int i, j;b[0]=true;b[1]=true;for(i=4; i<=1000000; i+=2){b[i]=true;}for(i=3; i<=1001; i+=2){if(!b[i]){for(j=i*i; j<=1000001; j+=2*i){b[j]=true;}}}}
// power ll power(ll a,ll b){if(b==0)return 1LL;if(b&1)return a*power(a,b-1);else{ll x=power(a,b/2);return x*x;}}
//bigmod long long int m(long long int a,long long int b,long long int c){if(b==0)return 1;if(b%2==0){long long int  tmp=m(a,b/2,c);return ((tmp%c)*(tmp%c))%c;}elsereturn ((a%c)*(m(a,b-1,c)%c))%c;}
//MaxSubarraySum ll mss(vector<ll>v){ll mx=v[0];ll sz=v.size();for(int i=1;i<=sz;i++){ll t=v[i]+v[i-1];if(t>=v[i]) v[i]=t;mx=max(mx,v[i]*1LL);}return mx;}
//combination ll com[1001][1001];void combination(){com[1][1]=1;com[1][0]=1;for(ll i=2; i<=1000; i++){com[i][0]=1;for(ll j=1; j<=i; j++){com[i][j]=com[i-1][j]+com[i-1][j-1];}}}
///--------------Graph Moves--------------------------------------
///const int fx[] = {+1,-1,+0,+0};
///const int fy[] = {+0,+0,+1,-1};
///const int fx[] = {+0,+0,+1,-1,-1,+1,-1,+1}; ///King's move
///const int fy[] = {-1,+1,+0,+0,+1,+1,-1,-1}; ///king's Move
///const int fx[] = {-2,-2,-1,-1,+1,+1,+2,+2}; ///knight's move
///const int fy[] = {-1,+1,-2,+2,-2,+2,-1,+1}; ///knight's move
///---------------------------------------------------------------
ll v[105][105];
bool vis[105][105];
void solve()
{
    memset(v,0,sizeof v);
    memset(vis,false,sizeof vis);
    ll a,b;
    cin>>a>>b;
    fr(i,1,a) fr(j,1,b) cin>>v[i][j];
    fr(i,1,a)
    {
        fr(j,1,b)
        {
            if(vis[i][j])
                continue;
            if(v[i+1][j]==v[i][j]||v[i-1][j]==v[i][j]||v[i][j+1]==v[i][j]||v[i][j-1]==v[i][j])
            {
                v[i][j]++;
                vis[i][j]=1;
                vis[i+1][j]=1;
                vis[i-1][j]=1;
                vis[i][j+1]=1;
                vis[i][j-1]=1;
            }
        }
    }
    fr(i,1,a)
    {
        fr(j,1,b)
        {
            if(vis[i][j])
                continue;
            if(v[i+1][j]==v[i][j]||v[i-1][j]==v[i][j]||v[i][j+1]==v[i][j]||v[i][j-1]==v[i][j])
            {
                v[i][j]++;
                vis[i][j]=1;
                vis[i+1][j]=1;
                vis[i-1][j]=1;
                vis[i][j+1]=1;
                vis[i][j-1]=1;
            }
        }
    }
    fr(i,1,a)
    {
        fr(j,1,b) cout<<v[i][j]<<' ';
        cout<<endl;
    }
}
int main()
{
    rj
    tst
    solve();
    return 0;
}


#include<bits/stdc++.h>
#define x first
#define y second
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()
#define mem(x,val) memset(x,val,sizeof x)
#define pii pair<int,int>
#define pb emplace_back
#define ar array
#define int long long
#define wopen(x) freopen((x),"w",stdout)
#define ropen(x) freopen((x),"r",stdin)
using namespace std;
const int dx[] = {1, 0, -1, 0}, dy[] = {0, 1, 0, -1};
int n, m, mat[205][205], add[205][205];

signed main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int T;
    cin >> T;
    while(T--){
        cin >> n >> m;
        mem(mat, 0);
        mem(add, 0);
        for(int i = 1; i <= n; i++)
            for(int j = 1; j <= m; j++) cin >> mat[i][j];

        for(int i = 1; i <= n; i++){
            for(int j = 1; j <= m; j++){
                if(mat[i][j] == mat[i][j-1]) mat[i][j]++, add[i][j] = 1;
            }
        }
        for(int j = 1; j <= m; j++)
        for(int i = 1; i <= n; i++){
            if(mat[i][j] == mat[i-1][j]) mat[i][j] += (add[i][j] ? -1 : 1);
        }
        for(int i = 1; i <= n; i++)
        for(int j = 1; j <= m; j++) {
            cout << mat[i][j] << ' ';
            if(j == m) cout << '\n';
        }
    }
}


#include<bits/stdc++.h>
#define x first
#define y second
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()
#define mem(x,val) memset(x,val,sizeof x)
#define pii pair<int,int>
#define pb emplace_back
#define ar array
#define int long long
#define wopen(x) freopen((x),"w",stdout)
#define ropen(x) freopen((x),"r",stdin)
using namespace std;
const int dx[] = {1, 0, -1, 0}, dy[] = {0, 1, 0, -1};
int n, m, mat[205][205], add[205][205];

signed main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int T;
    cin >> T;
    while(T--){
        cin >> n >> m;
        mem(mat, 0);
        mem(add, 0);
        for(int i = 1; i <= n; i++)
            for(int j = 1; j <= m; j++) cin >> mat[i][j];

        for(int i = 1; i <= n; i++){
            for(int j = 1; j <= m; j++){
                int t1 = 0, t2 = 0;
                for(int k = 0; k < 4; k++){
                    int nx = i + dx[k], ny = j + dy[k];
                    if(mat[nx][ny] == mat[i][j]) t1++;
                    if(mat[nx][ny] == mat[i][j] + 1) t2++;
                }
                if(t2 == 0 && t1) mat[i][j]++, add[i][j]++;
            }
        }

        for(int i = 1; i <= n; i++){
            for(int j = 1; j <= m; j++){
                if(mat[i][j] == mat[i][j+1] || mat[i][j] == mat[i+1][j] || mat[i][j] == mat[i-1][j] || mat[i][j] == mat[i][j-1]){
                    mat[i][j]++;
                }
            }
        }
        for(int i = 1; i <= n; i++)
        for(int j = 1; j <= m; j++) {
            cout << mat[i][j] << ' ';
            if(j == m) cout << '\n';
        }
    }
}


#include<bits/stdc++.h>
#define x first
#define y second
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()
#define mem(x,val) memset(x,val,sizeof x)
#define pii pair<int,int>
#define pb emplace_back
#define ar array
#define int long long
#define wopen(x) freopen((x),"w",stdout)
#define ropen(x) freopen((x),"r",stdin)
using namespace std;
const int dx[] = {1, 0, -1, 0}, dy[] = {0, 1, 0, -1};
int n, m, mat[205][205], add[205][205];

signed main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int T;
    cin >> T;
    while(T--){
        cin >> n >> m;
        mem(mat, 0);
        mem(add, 0);
        for(int i = 1; i <= n; i++)
            for(int j = 1; j <= m; j++) cin >> mat[i][j];

        for(int i = 1; i <= n; i++){
            for(int j = 1; j <= m; j++){
                int t1 = 0, t2 = 0;
                for(int k = 0; k < 4; k++){
                    int nx = i + dx[k], ny = j + dy[k];
                    if(mat[nx][ny] == mat[i][j]) t1++;
                    if(mat[nx][ny] == mat[i][j] + 1) t2++;
                }
                if(t2 == 0 && t1) mat[i][j]++;
            }
        }
        for(int i = 1; i <= n; i++)
        for(int j = 1; j <= m; j++) {
            cout << mat[i][j] << ' ';
            if(j == m) cout << '\n';
        }
    }
}


#include<bits/stdc++.h>
#define x first
#define y second
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()
#define mem(x,val) memset(x,val,sizeof x)
#define pii pair<int,int>
#define pb emplace_back
#define ar array
#define int long long
#define wopen(x) freopen((x),"w",stdout)
#define ropen(x) freopen((x),"r",stdin)
using namespace std;
const int dx[] = {1, 0, -1, 0}, dy[] = {0, 1, 0, -1};
int n, m, mat[205][205], add[205][205];

signed main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int T;
    cin >> T;
    while(T--){
        cin >> n >> m;
        mem(mat, 0);
        mem(add, 0);
        for(int i = 1; i <= n; i++)
            for(int j = 1; j <= m; j++) cin >> mat[i][j];
        for(int i = 1; i <= n; i++){
            for(int j = 1; j <= m; j++){
                if((i+j)&(mat[i][j])&1){
                    mat[i][j]++;
                }
            }
        }
        for(int i = 1; i <= n; i++)
        for(int j = 1; j <= m; j++) {
            cout << mat[i][j] << ' ';
            if(j == m) cout << '\n';
        }
    }
}


#include<bits/stdc++.h>
#define x first
#define y second
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()
#define mem(x,val) memset(x,val,sizeof x)
#define pii pair<int,int>
#define pb emplace_back
#define ar array
#define int long long
#define wopen(x) freopen((x),"w",stdout)
#define ropen(x) freopen((x),"r",stdin)
using namespace std;
const int dx[] = {1, 0, -1, 0}, dy[] = {0, 1, 0, -1};
int n, m, mat[205][205], add[205][205];

signed main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int T;
    cin >> T;
    while(T--){
        cin >> n >> m;
        mem(mat, 0);
        mem(add, 0);
        for(int i = 1; i <= n; i++)
            for(int j = 1; j <= m; j++) cin >> mat[i][j];
        int bit = 0;
        for(int i = 1; i <= n; i++){
            for(int j = 1; j <= m; j++){
                if(bit&1 != mat[i][j]&1){
                    mat[i][j]++;
                }
                bit^=1;
            }
        }
        for(int i = 1; i <= n; i++)
        for(int j = 1; j <= m; j++) {
            cout << mat[i][j] << ' ';
            if(j == m) cout << '\n';
        }
    }
}


#include<bits/stdc++.h>
#define x first
#define y second
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()
#define mem(x,val) memset(x,val,sizeof x)
#define pii pair<int,int>
#define pb emplace_back
#define ar array
#define int long long
#define wopen(x) freopen((x),"w",stdout)
#define ropen(x) freopen((x),"r",stdin)
using namespace std;
const int dx[] = {1, 0, -1, 0}, dy[] = {0, 1, 0, -1};
int n, m, mat[205][205], add[205][205];

signed main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int T;
    cin >> T;
    while(T--){
        cin >> n >> m;
        mem(mat, 0);
        mem(add, 0);
        for(int i = 1; i <= n; i++)
            for(int j = 1; j <= m; j++) cin >> mat[i][j];

        for(int i = 1; i <= n; i++){
            for(int j = 1; j <= m; j++){
                int t1 = 0, t2 = 0;
                for(int k = 0; k < 4; k++){
                    int nx = i + dx[k], ny = j + dy[k];
                    if(mat[nx][ny] == mat[i][j]) t1++;
                    if(mat[nx][ny] == mat[i][j] + 1) t2++;
                }
                if(t2 == 0 && t1) mat[i][j]++, add[i][j]++;
            }
        }

        for(int i = 1; i <= n; i++){
            for(int j = 1; j <= m; j++){
                if(add[i][j]) continue;
                if(mat[i][j] == mat[i][j+1] || mat[i][j] == mat[i+1][j] || mat[i][j] == mat[i-1][j] || mat[i][j] == mat[i][j-1]){
                    mat[i][j]++;
                }
            }
        }
        for(int i = 1; i <= n; i++)
        for(int j = 1; j <= m; j++) {
            cout << mat[i][j] << ' ';
            if(j == m) cout << '\n';
        }
    }
}


#include<bits/stdc++.h>
#define x first
#define y second
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()
#define mem(x,val) memset(x,val,sizeof x)
#define pii pair<int,int>
#define pb emplace_back
#define ar array
#define int long long
#define wopen(x) freopen((x),"w",stdout)
#define ropen(x) freopen((x),"r",stdin)
using namespace std;
const int dx[] = {1, 0, -1, 0}, dy[] = {0, 1, 0, -1};
int n, m, mat[205][205], add[205][205];

signed main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int T;
    cin >> T;
    while(T--){
        cin >> n >> m;
        mem(mat, 0);
        mem(add, 0);
        for(int i = 1; i <= n; i++)
            for(int j = 1; j <= m; j++) cin >> mat[i][j];
        int bit = 0;
        for(int i = 1; i <= n; i++){
            for(int j = 1; j <= m; j++){
                if((bit&1) != (mat[i][j]&1)){
                    mat[i][j]++;
                }
                bit^=1;
            }
        }
        for(int i = 1; i <= n; i++)
        for(int j = 1; j <= m; j++) {
            cout << mat[i][j] << ' ';
            if(j == m) cout << '\n';
        }
    }
}


#include<bits/stdc++.h>
#define x first
#define y second
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()
#define mem(x,val) memset(x,val,sizeof x)
#define pii pair<int,int>
#define pb emplace_back
#define ar array
#define int long long
#define wopen(x) freopen((x),"w",stdout)
#define ropen(x) freopen((x),"r",stdin)
using namespace std;
const int dx[] = {1, 0, -1, 0}, dy[] = {0, 1, 0, -1};
int n, m, mat[205][205], add[205][205];

signed main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int T;
    cin >> T;
    while(T--){
        cin >> n >> m;
        mem(mat, 0);
        mem(add, 0);
        for(int i = 1; i <= n; i++)
            for(int j = 1; j <= m; j++) cin >> mat[i][j];
        int bit = 0;
        for(int i = 1; i <= n; i++){
            for(int j = 1; j <= m; j++){
                if(bit != mat[i][j]&1){
                    mat[i][j]++;
                }
                bit^=1;
            }
        }
        for(int i = 1; i <= n; i++)
        for(int j = 1; j <= m; j++) {
            cout << mat[i][j] << ' ';
            if(j == m) cout << '\n';
        }
    }
}


#include<bits/stdc++.h>
#define x first
#define y second
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()
#define mem(x,val) memset(x,val,sizeof x)
#define pii pair<int,int>
#define pb emplace_back
#define ar array
#define int long long
#define wopen(x) freopen((x),"w",stdout)
#define ropen(x) freopen((x),"r",stdin)
using namespace std;
const int dx[] = {1, 0, -1, 0}, dy[] = {0, 1, 0, -1};
int n, m, mat[205][205], add[205][205];

signed main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int T;
    cin >> T;
    while(T--){
        cin >> n >> m;
        mem(mat, 0);
        mem(add, 0);
        for(int i = 1; i <= n; i++)
            for(int j = 1; j <= m; j++) cin >> mat[i][j];
        for(int i = 1; i <= n; i++){
            for(int j = 1; j <= m; j++){
                if(((i+j)&1) != (mat[i][j]&1)){
                    mat[i][j]++;
                }
            }
        }
        for(int i = 1; i <= n; i++)
        for(int j = 1; j <= m; j++) {
            cout << mat[i][j] << ' ';
            if(j == m) cout << '\n';
        }
    }
}


#ifndef LOCAL
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization ("unroll-loops")
#endif
#include "bits/stdc++.h"
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update
#include <ext/pb_ds/detail/standard_policies.hpp>
using namespace std;
using namespace __gnu_pbds;
#define sim template < class c
#define int long long
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << '\n'; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
    *this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
#define fastio ios_base::sync_with_stdio(false);cin.tie(0);
typedef tree< pair<int,int>, null_type, less<pair<int,int> >, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
typedef long long ll;
const ll MOD = 1e9 + 7 ;
const ll N = 2e5 + 10 ;
const ll INF = 1e18 + 10 ;
int n , m ;
vector<vector<int> > v , mark ;
vector<int> X = {1, -1, 0, 0} ;
vector<int> Y = {0,  0,-1, 1} ;
void solve(){
    cin >> n >> m ;
    v = vector<vector<int> >(n + 2, vector<int>(m + 2, -1)) ;
    mark = vector<vector<int> >(n + 2, vector<int>(m + 2, 0)) ;
    for(int i = 1; i <= n; i++){
        for(int j = 1; j <= m; j++){
            cin >> v[i][j] ;
        }
    }
    for(int i = 1; i <= n; i+= 2){
        for(int j = 1; j <= m; j+= 2){
            for(int k = 0; k < 4; k++){
                if ( v[i + X[k]][j + Y[k]] == v[i][j] ) {
                    v[i + X[k]][j + Y[k]]++ ;
                }
            }
        }
    }
    for(int i = 1; i <= n; i++){
        for(int j = 1; j <= m; j++){
            cout << v[i][j] << ' ' ;
        }
        cout << endl;
    }
}
signed main(){
    fastio
    int t ;
    cin >> t ;
    while(t--){
        solve() ;
    }
    return 0;
}


#ifndef LOCAL
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization ("unroll-loops")
#endif
#include "bits/stdc++.h"
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update
#include <ext/pb_ds/detail/standard_policies.hpp>
using namespace std;
using namespace __gnu_pbds;
#define sim template < class c
#define int long long
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << '\n'; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
    *this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
#define fastio ios_base::sync_with_stdio(false);cin.tie(0);
typedef tree< pair<int,int>, null_type, less<pair<int,int> >, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
typedef long long ll;
const ll MOD = 1e9 + 7 ;
const ll N = 2e5 + 10 ;
const ll INF = 1e18 + 10 ;
void solve(){
    int n , m ;
    cin >> n >> m ;
    vector<vector<int> > v(n, vector<int>(m)) ;
    for(int i = 0; i < n; i++){
        for(int j = 0; j < m; j++){
            cin >> v[i][j] ;
            if ( (i + j) & 1 ){
                if ( v[i][j] % 2 == 0 ) {
                    v[i][j]++ ;
                }
            }
            else {
                if ( v[i][j] % 2 == 1 ){
                    v[i][j]++ ;
                }
            }
        }
    }
    for(int i = 0; i < n; i++){
        for(int j = 0; j < m; j++){
            cout << v[i][j] << ' ' ;
        }
        cout << endl;
    }
}
signed main(){
    fastio
    int t ;
    cin >> t ;
    while(t--){
        solve() ;
    }
    return 0;
}


#ifndef LOCAL
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization ("unroll-loops")
#endif
#include "bits/stdc++.h"
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update
#include <ext/pb_ds/detail/standard_policies.hpp>
using namespace std;
using namespace __gnu_pbds;
#define sim template < class c
#define int long long
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << '\n'; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
    *this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
#define fastio ios_base::sync_with_stdio(false);cin.tie(0);
typedef tree< pair<int,int>, null_type, less<pair<int,int> >, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
typedef long long ll;
const ll MOD = 1e9 + 7 ;
const ll N = 2e5 + 10 ;
const ll INF = 1e18 + 10 ;
int n , m ;
vector<vector<int> > v , mark ;
vector<int> X = {1, -1, 0, 0} ;
vector<int> Y = {0,  0,-1, 1} ;
void solve(){
    cin >> n >> m ;
    v = vector<vector<int> >(n + 2, vector<int>(m + 2, -1)) ;
    mark = vector<vector<int> >(n + 2, vector<int>(m + 2, 0)) ;
    for(int i = 1; i <= n; i++){
        for(int j = 1; j <= m; j++){
            cin >> v[i][j] ;
        }
    }
    for(int i = 1; i <= n; i++){
        if ( i & 1 ) {
            for(int j = 1; j <= m; j += 2){
                if ( v[i][j] & 1 ) v[i][j]++ ;
            }
        }
        else {
            for(int j = 2; j <= m; j += 2){
                if ( v[i][j] & 1 ) v[i][j]++ ;
            }
        }
    }
    for(int i = 1; i <= n; i++){
        if ( i & 1 ) {
            for(int j = 2; j <= m; j += 2){
                if ( v[i][j] % 2 == 0 ) v[i][j]++ ;
            }
        }
        else {
            for(int j = 1; j <= m; j += 2){
                if ( v[i][j] % 2 == 0 ) v[i][j]++ ;
            }
        }
    }
    for(int i = 1; i <= n; i++){
        for(int j = 1; j <= m; j++){
            cout << v[i][j] << ' ' ;
        }
        cout << endl;
    }
}
signed main(){
    fastio
    int t ;
    cin >> t ;
    while(t--){
        solve() ;
    }
    return 0;
}


#ifndef LOCAL
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization ("unroll-loops")
#endif
#include "bits/stdc++.h"
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update
#include <ext/pb_ds/detail/standard_policies.hpp>
using namespace std;
using namespace __gnu_pbds;
#define sim template < class c
#define int long long
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << '\n'; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
    *this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
#define fastio ios_base::sync_with_stdio(false);cin.tie(0);
typedef tree< pair<int,int>, null_type, less<pair<int,int> >, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
typedef long long ll;
const ll MOD = 1e9 + 7 ;
const ll N = 2e5 + 10 ;
const ll INF = 1e18 + 10 ;
int n , m ;
vector<vector<int> > v , mark ;
void solve(){
    cin >> n >> m ;
    v = vector<vector<int> >(n + 2, vector<int>(m + 2, -1)) ;
    mark = vector<vector<int> >(n + 2, vector<int>(m + 2, 0)) ;
    for(int i = 1; i <= n; i++){
        for(int j = 1; j <= m; j++){
            cin >> v[i][j] ;
        }
    }
    vector<int> X = {1, -1, 0, 0} ;
    vector<int> Y = {0,  0,-1, 1} ;
    vector<int> c = {4, 3, 2, 1} ;
    for(int p = 9; p > 0; p--){
        bool ok = false ;
        for(int i = 1; i <= n; i++){
            for(int j = 1; j <= m; j++){
                if ( mark[i][j] ) continue ;
                int cnt = 0 ;
                for(int k = 0; k < 4; k++){
                    if ( v[i + X[k]][j + Y[k]] == v[i][j] ){
                        cnt++ ;
                    }
                }
                if ( cnt == p ) {
                    v[i][j]++ ;
                    mark[i][j] = true ;
                    ok = true ;
                }
            }
            if ( ok ) p = 9 ;
        }
        // debug() << "====" ;
        // for(int i = 1; i <= n; i++){
        //     for(int j = 1; j <= m; j++){
        //         cout << v[i][j] << ' ' ;
        //     }
        //     cout << endl;
        // }
        // debug() << "====" ;
    }
    for(int i = 1; i <= n; i++){
        for(int j = 1; j <= m; j++){
            cout << v[i][j] << ' ' ;
        }
        cout << endl;
    }
}
signed main(){
    fastio
    int t ;
    cin >> t ;
    while(t--){
        solve() ;
    }
    return 0;
}


#ifndef LOCAL
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization ("unroll-loops")
#endif
#include "bits/stdc++.h"
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update
#include <ext/pb_ds/detail/standard_policies.hpp>
using namespace std;
using namespace __gnu_pbds;
#define sim template < class c
#define int long long
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << '\n'; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
    *this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
#define fastio ios_base::sync_with_stdio(false);cin.tie(0);
typedef tree< pair<int,int>, null_type, less<pair<int,int> >, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
typedef long long ll;
const ll MOD = 1e9 + 7 ;
const ll N = 2e5 + 10 ;
const ll INF = 1e18 + 10 ;
int n , m ;
vector<vector<int> > v , mark ;
vector<int> X = {1, -1, 0, 0} ;
vector<int> Y = {0,  0,-1, 1} ;
void solve(){
    cin >> n >> m ;
    v = vector<vector<int> >(n + 2, vector<int>(m + 2, -1)) ;
    mark = vector<vector<int> >(n + 2, vector<int>(m + 2, 0)) ;
    for(int i = 1; i <= n; i++){
        for(int j = 1; j <= m; j++){
            cin >> v[i][j] ;
        }
    }
    for(int i = 1; i <= n; i++){
        for(int j = 1; j <= m; j++){
            for(int k = 0; k < 4; k++){
                if (  v[i + X[k]][j + Y[k]] == v[i][j] ) {
                    v[i + X[k]][j + Y[k]]++ ;
                    mark[i + X[k]][j + Y[k]] = true ;
                    mark[i][j] = true ;
                }
            }
        }
    }
    for(int i = 1; i <= n; i++){
        for(int j = 1; j <= m; j++){
            cout << v[i][j] << ' ' ;
        }
        cout << endl;
    }
}
signed main(){
    fastio
    int t ;
    cin >> t ;
    while(t--){
        solve() ;
    }
    return 0;
}


#ifndef LOCAL
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization ("unroll-loops")
#endif
#include "bits/stdc++.h"
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update
#include <ext/pb_ds/detail/standard_policies.hpp>
using namespace std;
using namespace __gnu_pbds;
#define sim template < class c
#define int long long
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << '\n'; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
    *this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
#define fastio ios_base::sync_with_stdio(false);cin.tie(0);
typedef tree< pair<int,int>, null_type, less<pair<int,int> >, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
typedef long long ll;
const ll MOD = 1e9 + 7 ;
const ll N = 2e5 + 10 ;
const ll INF = 1e18 + 10 ;
int n , m ;
vector<vector<int> > v , mark ;
vector<int> X = {1, -1, 0, 0} ;
vector<int> Y = {0,  0,-1, 1} ;
void solve(){
    cin >> n >> m ;
    v = vector<vector<int> >(n + 2, vector<int>(m + 2, -1)) ;
    mark = vector<vector<int> >(n + 2, vector<int>(m + 2, 0)) ;
    for(int i = 1; i <= n; i++){
        for(int j = 1; j <= m; j++){
            cin >> v[i][j] ;
        }
    }
    for(int i = 1; i <= n; i++){
        for(int j = 1; j <= m; j++){
            for(int k = 0; k < 4; k++){
                if ( v[i + X[k]][j + Y[k]] == v[i][j] ) {
                    v[i + X[k]][j + Y[k]]++ ;
                }
            }
        }
    }
    for(int i = 1; i <= n; i++){
        for(int j = 1; j <= m; j++){
            cout << v[i][j] << ' ' ;
        }
        cout << endl;
    }
}
signed main(){
    fastio
    int t ;
    cin >> t ;
    while(t--){
        solve() ;
    }
    return 0;
}


#ifndef LOCAL
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization ("unroll-loops")
#endif
#include "bits/stdc++.h"
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update
#include <ext/pb_ds/detail/standard_policies.hpp>
using namespace std;
using namespace __gnu_pbds;
#define sim template < class c
#define int long long
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << '\n'; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
    *this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
#define fastio ios_base::sync_with_stdio(false);cin.tie(0);
typedef tree< pair<int,int>, null_type, less<pair<int,int> >, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
typedef long long ll;
const ll MOD = 1e9 + 7 ;
const ll N = 2e5 + 10 ;
const ll INF = 1e18 + 10 ;
int n , m ;
vector<vector<int> > v , mark ;
vector<int> X = {1, -1, 0, 0} ;
vector<int> Y = {0,  0,-1, 1} ;
void solve(){
    cin >> n >> m ;
    v = vector<vector<int> >(n + 2, vector<int>(m + 2, -1)) ;
    mark = vector<vector<int> >(n + 2, vector<int>(m + 2, 0)) ;
    for(int i = 1; i <= n; i++){
        for(int j = 1; j <= m; j++){
            cin >> v[i][j] ;
        }
    }
    for(int i = 1; i <= n; i++){
        for(int j = 1; j <= m; j++){
            for(int k = 0; k < 4; k++){
                if ( not mark[i + X[k]][j + Y[k]] && v[i + X[k]][j + Y[k]] == v[i][j] ) {
                    v[i + X[k]][j + Y[k]]++ ;
                    mark[i + X[k]][j + Y[k]] = true ;
                }
            }
        }
    }
    for(int i = 1; i <= n; i++){
        for(int j = 1; j <= m; j++){
            cout << v[i][j] << ' ' ;
        }
        cout << endl;
    }
}
signed main(){
    fastio
    int t ;
    cin >> t ;
    while(t--){
        solve() ;
    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;

#define ms(s, n) memset(s, n, sizeof(s))
#define f(i, a, b) for (int i = (a); i <=(b); i++)
#define FORd(i, a, b) for (int i = (a) - 1; i >= (b); i--)
#define FORall(it, a) for (__typeof((a).begin()) it = (a).begin(); it != (a).end(); it++)
#define sz(a) int((a).size())
#define present(t, x) (t.find(x) != t.end())
#define all(a) (a).begin(), (a).end()
#define uni(a) (a).erase(unique(all(a)), (a).end())
#define pb push_back
#define pf push_front
#define mp make_pair
#define fi first
#define se second
#define prec(n) fixed<<setprecision(n)
#define bit(n, i) (((n) >> (i)) & 1)
#define bitcount(n) __builtin_popcountll(n)
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int, int> pi;
typedef vector<ll> vi;
typedef vector<pi> vii;
const int MOD = (int) 1e9 + 7;
const int MOD2 = MOD + 2; //1007681537;
const int INF = (int) 1e9;
const ll LINF = (ll) 1e18;
const ld PI = acos((ld) - 1);
const ld EPS = 1e-9;
inline ll gcd(ll a, ll b) {ll r; while (b) {r = a % b; a = b; b = r;} return a;}
inline ll lcm(ll a, ll b) {return a / gcd(a, b) * b;}
inline ll fpow(ll n, ll k, int p = MOD) {ll r = 1; for (; k; k >>= 1) {if (k & 1) r = r * n % p; n = n * n % p;} return r;}
template<class T> inline int chkmin(T& a, const T& val) {return val < a ? a = val, 1 : 0;}
template<class T> inline int chkmax(T& a, const T& val) {return a < val ? a = val, 1 : 0;}
inline ll isqrt(ll k) {ll r = sqrt(k) + 1; while (r * r > k) r--; return r;}
inline ll icbrt(ll k) {ll r = cbrt(k) + 1; while (r * r * r > k) r--; return r;}
inline void addmod(int& a, int val, int p = MOD) {if ((a = (a + val)) >= p) a -= p;}
inline void submod(int& a, int val, int p = MOD) {if ((a = (a - val)) < 0) a += p;}
inline int mult(int a, int b, int p = MOD) {return (ll) a * b % p;}
inline int inv(int a, int p = MOD) {return fpow(a, p - 2, p);}
inline int sign(ld x) {return x < -EPS ? -1 : x > +EPS;}
inline int sign(ld x, ld y) {return sign(x - y);}
int modulo(int a, int b) { return (a % b + b) % b; }
#define db(x) cerr << #x << " = " << (x) << " ";
#define endln cerr << "\n";

vector<vi>a;
ll n, m;
vector<vector<bool>>vis, inc;
bool valid(ll i, ll j) {
	if (i + 1 < n && a[i][j] + 1 == a[i + 1][j] && inc[i + 1][j]) {
		return 0;
	}
	if (j + 1 < m && a[i][j] + 1 == a[i][j + 1] && inc[i][j + 1]) {
		return 0;
	}
	if (i > 0 && a[i][j] + 1 == a[i - 1][j] && inc[i - 1][j]) {
		return 0;
	}
	if (j > 0 && a[i][j] + 1 == a[i][j - 1] && inc[i][j - 1]) {
		return 0;
	}
	return 1;
}
void dfs(ll i, ll j) {
	if (i < 0 || i >= n || j < 0 || j >= m || vis[i][j]) {
		return ;
	}
	vis[i][j] = 1;
	//cout << i << " " << j << ": \n";
	bool f = 1;
	if (j + 1 < m && a[i][j] == a[i][j + 1]) {
		if (f && valid(i, j) && !inc[i][j]) {
			//cout << "f " << i << " " << j + 1 << "\n";
			a[i][j]++;
			inc[i][j] = 1;
			f = 0;
		}
		else if (valid(i, j + 1) && !inc[i][j + 1]) {
			//cout << i << " " << j + 1 << "\n";
			a[i][j + 1]++;
			inc[i][j + 1] = 1;
			dfs(i, j + 1);
		}
	}
	if (j > 0 && a[i][j] == a[i][j - 1]) {
		if (f && valid(i, j) && !inc[i][j]) {
			//cout << "f " << i << " " << j - 1 << "\n";
			a[i][j]++; inc[i][j] = 1; f = 0;
		}
		else if (valid(i, j - 1) && !inc[i][j - 1]) {
			//cout <<  i << " " << j - 1 << "\n";
			a[i][j - 1]++;
			inc[i][j - 1] = 1;
			dfs(i, j - 1);
		}
	}
	if (i + 1 < n && a[i][j] == a[i + 1][j]) {
		if (f && valid(i, j) && !inc[i][j]) {
			//cout << "f " << i + 1 << " " << j  << "\n";
			a[i][j]++; inc[i][j] = 1; f = 0;
		}
		else  if (valid(i + 1, j) && !inc[i + 1][j]) {
			//cout <<  i + 1 << " " << j  << "\n";
			a[i + 1][j]++;
			inc[i + 1][j] = 1;
			dfs(i + 1, j);
		}
	}
	if (i > 0 && a[i][j] == a[i - 1][j]) {
		if (f && valid(i, j) && !inc[i][j]) {
			//cout << "f " << i - 1 << " " << j << "\n";
			a[i][j]++; inc[i][j] = 1; f = 0;
		}
		else  if (valid(i - 1, j) && !inc[i - 1][j]) {
			//cout <<  i - 1 << " " << j  << "\n";
			a[i - 1][j]++;
			inc[i - 1][j] = 1;
			dfs(i - 1, j);
		}
	}
}
int main()
{
	IOS;
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	int t;
	cin >> t;
	while (t--) {
		cin >> n >> m;
		vector<vi> b(n, vi(m));
		a = vector<vi>(n, vi(m));
		vis = vector<vector<bool>>(n, vector<bool>(m, 0));
		inc = vector<vector<bool>>(n, vector<bool>(m, 0));
		f(i, 0, n - 1) {
			f(j, 0, m - 1) {
				cin >> a[i][j];
			}
		}
		//dfs(0, 0);
		f(i, 0, n - 1) {
			f(j, 0, m - 1) {
				if (vis[i][j])
					continue;
				dfs(i, j);
				// f(i, 0, n - 1) {
				// 	f(j, 0, m - 1) {
				// 		cout << a[i][j] << " ";
				// 	}
				// 	cout <<  "\n";
				// }
			}
		}
		f(i, 0, n - 1) {
			f(j, 0, m - 1) {
				cout << a[i][j] << " ";
			}
			cout <<  "\n";
		}
	}
// read the stuff at the bottom
	return 0;
}
/* stuff you should look for
	* int overflow, array bounds
	* special cases (n=1?)
	* do smth instead of nothing and stay organized
	* WRITE STUFF DOWN
	* use int when constraints limits are tight
	* Time taken : global variable < pass by refernce < pass by value
	* It takes significant amt. of time in pass by value
	* Avoid Using endl
*/


#include <bits/stdc++.h>
using namespace std;

#define ms(s, n) memset(s, n, sizeof(s))
#define f(i, a, b) for (int i = (a); i <=(b); i++)
#define FORd(i, a, b) for (int i = (a) - 1; i >= (b); i--)
#define FORall(it, a) for (__typeof((a).begin()) it = (a).begin(); it != (a).end(); it++)
#define sz(a) int((a).size())
#define present(t, x) (t.find(x) != t.end())
#define all(a) (a).begin(), (a).end()
#define uni(a) (a).erase(unique(all(a)), (a).end())
#define pb push_back
#define pf push_front
#define mp make_pair
#define fi first
#define se second
#define prec(n) fixed<<setprecision(n)
#define bit(n, i) (((n) >> (i)) & 1)
#define bitcount(n) __builtin_popcountll(n)
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int, int> pi;
typedef vector<ll> vi;
typedef vector<pi> vii;
const int MOD = (int) 1e9 + 7;
const int MOD2 = MOD + 2; //1007681537;
const int INF = (int) 1e9;
const ll LINF = (ll) 1e18;
const ld PI = acos((ld) - 1);
const ld EPS = 1e-9;
inline ll gcd(ll a, ll b) {ll r; while (b) {r = a % b; a = b; b = r;} return a;}
inline ll lcm(ll a, ll b) {return a / gcd(a, b) * b;}
inline ll fpow(ll n, ll k, int p = MOD) {ll r = 1; for (; k; k >>= 1) {if (k & 1) r = r * n % p; n = n * n % p;} return r;}
template<class T> inline int chkmin(T& a, const T& val) {return val < a ? a = val, 1 : 0;}
template<class T> inline int chkmax(T& a, const T& val) {return a < val ? a = val, 1 : 0;}
inline ll isqrt(ll k) {ll r = sqrt(k) + 1; while (r * r > k) r--; return r;}
inline ll icbrt(ll k) {ll r = cbrt(k) + 1; while (r * r * r > k) r--; return r;}
inline void addmod(int& a, int val, int p = MOD) {if ((a = (a + val)) >= p) a -= p;}
inline void submod(int& a, int val, int p = MOD) {if ((a = (a - val)) < 0) a += p;}
inline int mult(int a, int b, int p = MOD) {return (ll) a * b % p;}
inline int inv(int a, int p = MOD) {return fpow(a, p - 2, p);}
inline int sign(ld x) {return x < -EPS ? -1 : x > +EPS;}
inline int sign(ld x, ld y) {return sign(x - y);}
int modulo(int a, int b) { return (a % b + b) % b; }
#define db(x) cerr << #x << " = " << (x) << " ";
#define endln cerr << "\n";

vector<vi>a;
ll n, m;
vector<vector<bool>>vis, inc;
bool valid(ll i, ll j) {
	if (i + 1 < n && a[i][j] + 1 == a[i + 1][j] && inc[i + 1][j]) {
		return 0;
	}
	if (j + 1 < m && a[i][j] + 1 == a[i][j + 1] && inc[i][j + 1]) {
		return 0;
	}
	if (i > 0 && a[i][j] + 1 == a[i - 1][j] && inc[i - 1][j]) {
		return 0;
	}
	if (j > 0 && a[i][j] + 1 == a[i][j - 1] && inc[i][j - 1]) {
		return 0;
	}
	return 1;
}
void dfs(ll i, ll j) {
	if (i < 0 || i >= n || j < 0 || j >= m) {
		return ;
	}
	//vis[i][j] = 1;
	//cout << i << " " << j << ": \n";
	bool f = 1;
	if (j + 1 < m && a[i][j] == a[i][j + 1]) {
		if (f && valid(i, j) && !inc[i][j]) {
			//cout << "f " << i << " " << j + 1 << "\n";
			a[i][j]++;
			inc[i][j] = 1;
			f = 0;
		}
		else if (valid(i, j + 1) && !inc[i][j + 1]) {
			//cout << i << " " << j + 1 << "\n";
			a[i][j + 1]++;
			inc[i][j + 1] = 1;
			dfs(i, j + 1);
		}
	}
	if (j > 0 && a[i][j] == a[i][j - 1]) {
		if (f && valid(i, j) && !inc[i][j]) {
			//cout << "f " << i << " " << j - 1 << "\n";
			a[i][j]++; inc[i][j] = 1; f = 0;
		}
		else if (valid(i, j - 1) && !inc[i][j - 1]) {
			//cout <<  i << " " << j - 1 << "\n";
			a[i][j - 1]++;
			inc[i][j - 1] = 1;
			dfs(i, j - 1);
		}
	}
	if (i + 1 < n && a[i][j] == a[i + 1][j]) {
		if (f && valid(i, j) && !inc[i][j]) {
			//cout << "f " << i + 1 << " " << j  << "\n";
			a[i][j]++; inc[i][j] = 1; f = 0;
		}
		else  if (valid(i + 1, j) && !inc[i + 1][j]) {
			//cout <<  i + 1 << " " << j  << "\n";
			a[i + 1][j]++;
			inc[i + 1][j] = 1;
			dfs(i + 1, j);
		}
	}
	if (i > 0 && a[i][j] == a[i - 1][j]) {
		if (f && valid(i, j) && !inc[i][j]) {
			//cout << "f " << i - 1 << " " << j << "\n";
			a[i][j]++; inc[i][j] = 1; f = 0;
		}
		else  if (valid(i - 1, j) && !inc[i - 1][j]) {
			//cout <<  i - 1 << " " << j  << "\n";
			a[i - 1][j]++;
			inc[i - 1][j] = 1;
			dfs(i - 1, j);
		}
	}
}
int main()
{
	IOS;
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	int t;
	cin >> t;
	while (t--) {
		cin >> n >> m;
		vector<vi> b(n, vi(m));
		a = vector<vi>(n, vi(m));
		vis = vector<vector<bool>>(n, vector<bool>(m, 0));
		inc = vector<vector<bool>>(n, vector<bool>(m, 0));
		f(i, 0, n - 1) {
			f(j, 0, m - 1) {
				cin >> a[i][j];
			}
		}
		//dfs(0, 0);
		f(i, 0, n - 1) {
			f(j, 0, m - 1) {
				if (vis[i][j])
					continue;
				dfs(i, j);
				// f(i, 0, n - 1) {
				// 	f(j, 0, m - 1) {
				// 		cout << a[i][j] << " ";
				// 	}
				// 	cout <<  "\n";
				// }
			}
		}
		f(i, 0, n - 1) {
			f(j, 0, m - 1) {
				cout << a[i][j] << " ";
			}
			cout <<  "\n";
		}
	}
// read the stuff at the bottom
	return 0;
}
/* stuff you should look for
	* int overflow, array bounds
	* special cases (n=1?)
	* do smth instead of nothing and stay organized
	* WRITE STUFF DOWN
	* use int when constraints limits are tight
	* Time taken : global variable < pass by refernce < pass by value
	* It takes significant amt. of time in pass by value
	* Avoid Using endl
*/


#include <bits/stdc++.h>
using namespace std;

#define ms(s, n) memset(s, n, sizeof(s))
#define f(i, a, b) for (int i = (a); i <=(b); i++)
#define FORd(i, a, b) for (int i = (a) - 1; i >= (b); i--)
#define FORall(it, a) for (__typeof((a).begin()) it = (a).begin(); it != (a).end(); it++)
#define sz(a) int((a).size())
#define present(t, x) (t.find(x) != t.end())
#define all(a) (a).begin(), (a).end()
#define uni(a) (a).erase(unique(all(a)), (a).end())
#define pb push_back
#define pf push_front
#define mp make_pair
#define fi first
#define se second
#define prec(n) fixed<<setprecision(n)
#define bit(n, i) (((n) >> (i)) & 1)
#define bitcount(n) __builtin_popcountll(n)
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int, int> pi;
typedef vector<ll> vi;
typedef vector<pi> vii;
const int MOD = (int) 1e9 + 7;
const int MOD2 = MOD + 2; //1007681537;
const int INF = (int) 1e9;
const ll LINF = (ll) 1e18;
const ld PI = acos((ld) - 1);
const ld EPS = 1e-9;
inline ll gcd(ll a, ll b) {ll r; while (b) {r = a % b; a = b; b = r;} return a;}
inline ll lcm(ll a, ll b) {return a / gcd(a, b) * b;}
inline ll fpow(ll n, ll k, int p = MOD) {ll r = 1; for (; k; k >>= 1) {if (k & 1) r = r * n % p; n = n * n % p;} return r;}
template<class T> inline int chkmin(T& a, const T& val) {return val < a ? a = val, 1 : 0;}
template<class T> inline int chkmax(T& a, const T& val) {return a < val ? a = val, 1 : 0;}
inline ll isqrt(ll k) {ll r = sqrt(k) + 1; while (r * r > k) r--; return r;}
inline ll icbrt(ll k) {ll r = cbrt(k) + 1; while (r * r * r > k) r--; return r;}
inline void addmod(int& a, int val, int p = MOD) {if ((a = (a + val)) >= p) a -= p;}
inline void submod(int& a, int val, int p = MOD) {if ((a = (a - val)) < 0) a += p;}
inline int mult(int a, int b, int p = MOD) {return (ll) a * b % p;}
inline int inv(int a, int p = MOD) {return fpow(a, p - 2, p);}
inline int sign(ld x) {return x < -EPS ? -1 : x > +EPS;}
inline int sign(ld x, ld y) {return sign(x - y);}
int modulo(int a, int b) { return (a % b + b) % b; }
#define db(x) cerr << #x << " = " << (x) << " ";
#define endln cerr << "\n";

vector<vi>a;
ll n, m;
vector<vector<bool>>vis, inc;
bool valid(ll i, ll j) {
	if (i + 1 < n && a[i][j] + 1 == a[i + 1][j] && inc[i + 1][j]) {
		return 0;
	}
	if (j + 1 < m && a[i][j] + 1 == a[i][j + 1] && inc[i][j + 1]) {
		return 0;
	}
	if (i > 0 && a[i][j] + 1 == a[i - 1][j] && inc[i - 1][j]) {
		return 0;
	}
	if (j > 0 && a[i][j] + 1 == a[i][j - 1] && inc[i][j - 1]) {
		return 0;
	}
	return 1;
}
void dfs(ll i, ll j) {
	if (i < 0 || i >= n || j < 0 || j >= m) {
		return ;
	}
	vis[i][j] = 1;
	//cout << i << " " << j << ": \n";
	bool f = 1;
	if (j + 1 < m && a[i][j] == a[i][j + 1]) {
		if (f && valid(i, j) && !inc[i][j]) {
			//cout << "f " << i << " " << j + 1 << "\n";
			a[i][j]++;
			inc[i][j] = 1;
			f = 0;
		}
		else if (valid(i, j + 1) && !inc[i][j + 1]) {
			//cout << i << " " << j + 1 << "\n";
			a[i][j + 1]++;
			inc[i][j + 1] = 1;
			dfs(i, j + 1);
		}
	}
	if (j > 0 && a[i][j] == a[i][j - 1]) {
		if (f && valid(i, j) && !inc[i][j]) {
			//cout << "f " << i << " " << j - 1 << "\n";
			a[i][j]++; inc[i][j] = 1; f = 0;
		}
		else if (valid(i, j - 1) && !inc[i][j - 1]) {
			//cout <<  i << " " << j - 1 << "\n";
			a[i][j - 1]++;
			inc[i][j - 1] = 1;
			dfs(i, j - 1);
		}
	}
	if (i + 1 < n && a[i][j] == a[i + 1][j]) {
		if (f && valid(i, j) && !inc[i][j]) {
			//cout << "f " << i + 1 << " " << j  << "\n";
			a[i][j]++; inc[i][j] = 1; f = 0;
		}
		else  if (valid(i + 1, j) && !inc[i + 1][j]) {
			//cout <<  i + 1 << " " << j  << "\n";
			a[i + 1][j]++;
			inc[i + 1][j] = 1;
			dfs(i + 1, j);
		}
	}
	if (i > 0 && a[i][j] == a[i - 1][j]) {
		if (f && valid(i, j) && !inc[i][j]) {
			//cout << "f " << i - 1 << " " << j << "\n";
			a[i][j]++; inc[i][j] = 1; f = 0;
		}
		else  if (valid(i - 1, j) && !inc[i - 1][j]) {
			//cout <<  i - 1 << " " << j  << "\n";
			a[i - 1][j]++;
			inc[i - 1][j] = 1;
			dfs(i - 1, j);
		}
	}
}
int main()
{
	IOS;
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	int t;
	cin >> t;
	while (t--) {
		cin >> n >> m;
		vector<vi> b(n, vi(m));
		a = vector<vi>(n, vi(m));
		vis = vector<vector<bool>>(n, vector<bool>(m, 0));
		inc = vector<vector<bool>>(n, vector<bool>(m, 0));
		f(i, 0, n - 1) {
			f(j, 0, m - 1) {
				cin >> a[i][j];
			}
		}
		//dfs(0, 0);
		f(i, 0, n - 1) {
			f(j, 0, m - 1) {
				if (vis[i][j])
					continue;
				dfs(i, j);
				// f(i, 0, n - 1) {
				// 	f(j, 0, m - 1) {
				// 		cout << a[i][j] << " ";
				// 	}
				// 	cout <<  "\n";
				// }
			}
		}
		f(i, 0, n - 1) {
			f(j, 0, m - 1) {
				cout << a[i][j] << " ";
			}
			cout <<  "\n";
		}
	}
// read the stuff at the bottom
	return 0;
}
/* stuff you should look for
	* int overflow, array bounds
	* special cases (n=1?)
	* do smth instead of nothing and stay organized
	* WRITE STUFF DOWN
	* use int when constraints limits are tight
	* Time taken : global variable < pass by refernce < pass by value
	* It takes significant amt. of time in pass by value
	* Avoid Using endl
*/


#include <bits/stdc++.h>
using namespace std;

#define ms(s, n) memset(s, n, sizeof(s))
#define f(i, a, b) for (int i = (a); i <=(b); i++)
#define FORd(i, a, b) for (int i = (a) - 1; i >= (b); i--)
#define FORall(it, a) for (__typeof((a).begin()) it = (a).begin(); it != (a).end(); it++)
#define sz(a) int((a).size())
#define present(t, x) (t.find(x) != t.end())
#define all(a) (a).begin(), (a).end()
#define uni(a) (a).erase(unique(all(a)), (a).end())
#define pb push_back
#define pf push_front
#define mp make_pair
#define fi first
#define se second
#define prec(n) fixed<<setprecision(n)
#define bit(n, i) (((n) >> (i)) & 1)
#define bitcount(n) __builtin_popcountll(n)
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int, int> pi;
typedef vector<ll> vi;
typedef vector<pi> vii;
const int MOD = (int) 1e9 + 7;
const int MOD2 = MOD + 2; //1007681537;
const int INF = (int) 1e9;
const ll LINF = (ll) 1e18;
const ld PI = acos((ld) - 1);
const ld EPS = 1e-9;
inline ll gcd(ll a, ll b) {ll r; while (b) {r = a % b; a = b; b = r;} return a;}
inline ll lcm(ll a, ll b) {return a / gcd(a, b) * b;}
inline ll fpow(ll n, ll k, int p = MOD) {ll r = 1; for (; k; k >>= 1) {if (k & 1) r = r * n % p; n = n * n % p;} return r;}
template<class T> inline int chkmin(T& a, const T& val) {return val < a ? a = val, 1 : 0;}
template<class T> inline int chkmax(T& a, const T& val) {return a < val ? a = val, 1 : 0;}
inline ll isqrt(ll k) {ll r = sqrt(k) + 1; while (r * r > k) r--; return r;}
inline ll icbrt(ll k) {ll r = cbrt(k) + 1; while (r * r * r > k) r--; return r;}
inline void addmod(int& a, int val, int p = MOD) {if ((a = (a + val)) >= p) a -= p;}
inline void submod(int& a, int val, int p = MOD) {if ((a = (a - val)) < 0) a += p;}
inline int mult(int a, int b, int p = MOD) {return (ll) a * b % p;}
inline int inv(int a, int p = MOD) {return fpow(a, p - 2, p);}
inline int sign(ld x) {return x < -EPS ? -1 : x > +EPS;}
inline int sign(ld x, ld y) {return sign(x - y);}
int modulo(int a, int b) { return (a % b + b) % b; }
#define db(x) cerr << #x << " = " << (x) << " ";
#define endln cerr << "\n";

vector<vi>a;
ll n, m;
vector<vector<bool>>vis;
bool valid(ll i, ll j) {
	if (i + 1 < n && a[i][j] + 1 == a[i + 1][j] && vis[i + 1][j]) {
		return 0;
	}
	if (j + 1 < m && a[i][j] + 1 == a[i][j + 1] && vis[i][j + 1]) {
		return 0;
	}
	if (i > 0 && a[i][j] + 1 == a[i - 1][j] && vis[i - 1][j]) {
		return 0;
	}
	if (j > 0 && a[i][j] + 1 == a[i][j - 1] && vis[i][j - 1]) {
		return 0;
	}
	return 1;
}
void dfs(ll i, ll j) {
	if (i < 0 || i >= n || j < 0 || j >= m || vis[i][j]) {
		return ;
	}
	vis[i][j] = 1;
	//cout << i << " " << j << "\n";
	bool f = 1;
	if (j + 1 < m && a[i][j] == a[i][j + 1]) {
		if (f && valid(i, j)) {
			a[i][j]++;
			f = 0;
		}
		else {
			a[i][j + 1]++;
			dfs(i, j + 1);
		}
	}
	if (j > 0 && a[i][j] == a[i][j - 1]) {
		if (f && valid(i, j)) {
			a[i][j]++; f = 0;
		}
		else {
			a[i][j - 1]++;
			dfs(i, j - 1);
		}
	}
	if (i + 1 < n && a[i][j] == a[i + 1][j]) {
		if (f && valid(i, j)) {
			a[i][j]++; f = 0;
		}
		else {
			a[i + 1][j]++;
			dfs(i + 1, j);
		}
	}
	if (i > 0 && a[i][j] == a[i - 1][j]) {
		if (f && valid(i, j)) {
			a[i][j]++; f = 0;
		}
		else {
			a[i - 1][j]++;
			dfs(i - 1, j);
		}
	}
}
int main()
{
	IOS;
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	int t;
	cin >> t;
	while (t--) {
		cin >> n >> m;
		vector<vi> b(n, vi(m));
		a = vector<vi>(n, vi(m));
		vis = vector<vector<bool>>(n, vector<bool>(m, 0));
		f(i, 0, n - 1) {
			f(j, 0, m - 1) {
				cin >> a[i][j];
			}
		}
		//dfs(0, 0);
		f(i, 0, n - 1) {
			f(j, 0, m - 1) {
				if (vis[i][j])
					continue;
				dfs(i, j);
			}
		}
		f(i, 0, n - 1) {
			f(j, 0, m - 1) {
				cout << a[i][j] << " ";
			}
			cout <<  "\n";
		}
	}
// read the stuff at the bottom
	return 0;
}
/* stuff you should look for
	* int overflow, array bounds
	* special cases (n=1?)
	* do smth instead of nothing and stay organized
	* WRITE STUFF DOWN
	* use int when constraints limits are tight
	* Time taken : global variable < pass by refernce < pass by value
	* It takes significant amt. of time in pass by value
	* Avoid Using endl
*/


#include <bits/stdc++.h>
using namespace std;

#define ms(s, n) memset(s, n, sizeof(s))
#define f(i, a, b) for (int i = (a); i <=(b); i++)
#define FORd(i, a, b) for (int i = (a) - 1; i >= (b); i--)
#define FORall(it, a) for (__typeof((a).begin()) it = (a).begin(); it != (a).end(); it++)
#define sz(a) int((a).size())
#define present(t, x) (t.find(x) != t.end())
#define all(a) (a).begin(), (a).end()
#define uni(a) (a).erase(unique(all(a)), (a).end())
#define pb push_back
#define pf push_front
#define mp make_pair
#define fi first
#define se second
#define prec(n) fixed<<setprecision(n)
#define bit(n, i) (((n) >> (i)) & 1)
#define bitcount(n) __builtin_popcountll(n)
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int, int> pi;
typedef vector<ll> vi;
typedef vector<pi> vii;
const int MOD = (int) 1e9 + 7;
const int MOD2 = MOD + 2; //1007681537;
const int INF = (int) 1e9;
const ll LINF = (ll) 1e18;
const ld PI = acos((ld) - 1);
const ld EPS = 1e-9;
inline ll gcd(ll a, ll b) {ll r; while (b) {r = a % b; a = b; b = r;} return a;}
inline ll lcm(ll a, ll b) {return a / gcd(a, b) * b;}
inline ll fpow(ll n, ll k, int p = MOD) {ll r = 1; for (; k; k >>= 1) {if (k & 1) r = r * n % p; n = n * n % p;} return r;}
template<class T> inline int chkmin(T& a, const T& val) {return val < a ? a = val, 1 : 0;}
template<class T> inline int chkmax(T& a, const T& val) {return a < val ? a = val, 1 : 0;}
inline ll isqrt(ll k) {ll r = sqrt(k) + 1; while (r * r > k) r--; return r;}
inline ll icbrt(ll k) {ll r = cbrt(k) + 1; while (r * r * r > k) r--; return r;}
inline void addmod(int& a, int val, int p = MOD) {if ((a = (a + val)) >= p) a -= p;}
inline void submod(int& a, int val, int p = MOD) {if ((a = (a - val)) < 0) a += p;}
inline int mult(int a, int b, int p = MOD) {return (ll) a * b % p;}
inline int inv(int a, int p = MOD) {return fpow(a, p - 2, p);}
inline int sign(ld x) {return x < -EPS ? -1 : x > +EPS;}
inline int sign(ld x, ld y) {return sign(x - y);}
int modulo(int a, int b) { return (a % b + b) % b; }
#define db(x) cerr << #x << " = " << (x) << " ";
#define endln cerr << "\n";

vector<vi>a;
ll n, m;
vector<vector<bool>>vis, inc;
bool valid(ll i, ll j) {
	if (i + 1 < n && a[i][j] + 1 == a[i + 1][j] && inc[i + 1][j]) {
		return 0;
	}
	if (j + 1 < m && a[i][j] + 1 == a[i][j + 1] && inc[i][j + 1]) {
		return 0;
	}
	if (i > 0 && a[i][j] + 1 == a[i - 1][j] && inc[i - 1][j]) {
		return 0;
	}
	if (j > 0 && a[i][j] + 1 == a[i][j - 1] && inc[i][j - 1]) {
		return 0;
	}
	return 1;
}
void dfs(ll i, ll j) {
	if (i < 0 || i >= n || j < 0 || j >= m || vis[i][j]) {
		return ;
	}
	vis[i][j] = 1;
	//cout << i << " " << j << "\n";
	bool f = 1;
	if (j + 1 < m && a[i][j] == a[i][j + 1]) {
		if (f && valid(i, j)) {
			a[i][j]++;
			inc[i][j] = 1;
			f = 0;
		}
		else {
			a[i][j + 1]++;
			inc[i][j + 1] = 1;
			dfs(i, j + 1);
		}
	}
	if (j > 0 && a[i][j] == a[i][j - 1]) {
		if (f && valid(i, j)) {
			a[i][j]++; inc[i][j] = 1; f = 0;
		}
		else {
			a[i][j - 1]++;
			inc[i][j - 1] = 1;
			dfs(i, j - 1);
		}
	}
	if (i + 1 < n && a[i][j] == a[i + 1][j]) {
		if (f && valid(i, j)) {
			a[i][j]++; inc[i][j] = 1; f = 0;
		}
		else {
			a[i + 1][j]++;
			inc[i + 1][j] = 1;
			dfs(i + 1, j);
		}
	}
	if (i > 0 && a[i][j] == a[i - 1][j]) {
		if (f && valid(i, j)) {
			a[i][j]++; inc[i][j] = 1; f = 0;
		}
		else {
			a[i - 1][j]++;
			inc[i - 1][j] = 1;
			dfs(i - 1, j);
		}
	}
}
int main()
{
	IOS;
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	int t;
	cin >> t;
	while (t--) {
		cin >> n >> m;
		vector<vi> b(n, vi(m));
		a = vector<vi>(n, vi(m));
		vis = vector<vector<bool>>(n, vector<bool>(m, 0));
		inc = vector<vector<bool>>(n, vector<bool>(m, 0));
		f(i, 0, n - 1) {
			f(j, 0, m - 1) {
				cin >> a[i][j];
			}
		}
		//dfs(0, 0);
		f(i, 0, n - 1) {
			f(j, 0, m - 1) {
				if (vis[i][j])
					continue;
				dfs(i, j);
			}
		}
		f(i, 0, n - 1) {
			f(j, 0, m - 1) {
				cout << a[i][j] << " ";
			}
			cout <<  "\n";
		}
	}
// read the stuff at the bottom
	return 0;
}
/* stuff you should look for
	* int overflow, array bounds
	* special cases (n=1?)
	* do smth instead of nothing and stay organized
	* WRITE STUFF DOWN
	* use int when constraints limits are tight
	* Time taken : global variable < pass by refernce < pass by value
	* It takes significant amt. of time in pass by value
	* Avoid Using endl
*/


#include <bits/stdc++.h>
using namespace std;

#define ms(s, n) memset(s, n, sizeof(s))
#define f(i, a, b) for (int i = (a); i <=(b); i++)
#define FORd(i, a, b) for (int i = (a) - 1; i >= (b); i--)
#define FORall(it, a) for (__typeof((a).begin()) it = (a).begin(); it != (a).end(); it++)
#define sz(a) int((a).size())
#define present(t, x) (t.find(x) != t.end())
#define all(a) (a).begin(), (a).end()
#define uni(a) (a).erase(unique(all(a)), (a).end())
#define pb push_back
#define pf push_front
#define mp make_pair
#define fi first
#define se second
#define prec(n) fixed<<setprecision(n)
#define bit(n, i) (((n) >> (i)) & 1)
#define bitcount(n) __builtin_popcountll(n)
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int, int> pi;
typedef vector<ll> vi;
typedef vector<pi> vii;
const int MOD = (int) 1e9 + 7;
const int MOD2 = MOD + 2; //1007681537;
const int INF = (int) 1e9;
const ll LINF = (ll) 1e18;
const ld PI = acos((ld) - 1);
const ld EPS = 1e-9;
inline ll gcd(ll a, ll b) {ll r; while (b) {r = a % b; a = b; b = r;} return a;}
inline ll lcm(ll a, ll b) {return a / gcd(a, b) * b;}
inline ll fpow(ll n, ll k, int p = MOD) {ll r = 1; for (; k; k >>= 1) {if (k & 1) r = r * n % p; n = n * n % p;} return r;}
template<class T> inline int chkmin(T& a, const T& val) {return val < a ? a = val, 1 : 0;}
template<class T> inline int chkmax(T& a, const T& val) {return a < val ? a = val, 1 : 0;}
inline ll isqrt(ll k) {ll r = sqrt(k) + 1; while (r * r > k) r--; return r;}
inline ll icbrt(ll k) {ll r = cbrt(k) + 1; while (r * r * r > k) r--; return r;}
inline void addmod(int& a, int val, int p = MOD) {if ((a = (a + val)) >= p) a -= p;}
inline void submod(int& a, int val, int p = MOD) {if ((a = (a - val)) < 0) a += p;}
inline int mult(int a, int b, int p = MOD) {return (ll) a * b % p;}
inline int inv(int a, int p = MOD) {return fpow(a, p - 2, p);}
inline int sign(ld x) {return x < -EPS ? -1 : x > +EPS;}
inline int sign(ld x, ld y) {return sign(x - y);}
int modulo(int a, int b) { return (a % b + b) % b; }
#define db(x) cerr << #x << " = " << (x) << " ";
#define endln cerr << "\n";

vector<vi>a;
ll n, m;
void dfs(ll i, ll j) {
	//cout << i << " " << j << "\n";
	if (i < 0 || i >= n || j < 0 || j >= m) {
		return ;
	}
	if (j + 1 < m && a[i][j] == a[i][j + 1]) {
		a[i][j + 1]++;
		dfs(i, j + 1);
	}
	if (j > 0 && a[i][j] == a[i][j - 1]) {
		a[i][j - 1]++;
		dfs(i, j - 1);
	}
	if (i + 1 < n && a[i][j] == a[i + 1][j]) {
		a[i + 1][j]++;
		dfs(i + 1, j);
	}
	if (i > 0 && a[i][j] == a[i - 1][j]) {
		a[i - 1][j]++;
		dfs(i - 1, j);
	}
}
int main()
{
	IOS;
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	int t;
	cin >> t;
	while (t--) {
		cin >> n >> m;
		vector<vi> b(n, vi(m));
		a = vector<vi>(n, vi(m));
		f(i, 0, n - 1) {
			f(j, 0, m - 1) {
				cin >> a[i][j];
			}
		}
		//dfs(0, 0);
		f(i, 0, n - 1) {
			f(j, 0, m - 1) {
				dfs(i, j);
			}
		}
		f(i, 0, n - 1) {
			f(j, 0, m - 1) {
				cout << a[i][j] << " ";
			}
			cout <<  "\n";
		}
	}
// read the stuff at the bottom
	return 0;
}
/* stuff you should look for
	* int overflow, array bounds
	* special cases (n=1?)
	* do smth instead of nothing and stay organized
	* WRITE STUFF DOWN
	* use int when constraints limits are tight
	* Time taken : global variable < pass by refernce < pass by value
	* It takes significant amt. of time in pass by value
	* Avoid Using endl
*/


#include <bits/stdc++.h>
using namespace std;

#define ms(s, n) memset(s, n, sizeof(s))
#define f(i, a, b) for (int i = (a); i <=(b); i++)
#define FORd(i, a, b) for (int i = (a) - 1; i >= (b); i--)
#define FORall(it, a) for (__typeof((a).begin()) it = (a).begin(); it != (a).end(); it++)
#define sz(a) int((a).size())
#define present(t, x) (t.find(x) != t.end())
#define all(a) (a).begin(), (a).end()
#define uni(a) (a).erase(unique(all(a)), (a).end())
#define pb push_back
#define pf push_front
#define mp make_pair
#define fi first
#define se second
#define prec(n) fixed<<setprecision(n)
#define bit(n, i) (((n) >> (i)) & 1)
#define bitcount(n) __builtin_popcountll(n)
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int, int> pi;
typedef vector<ll> vi;
typedef vector<pi> vii;
const int MOD = (int) 1e9 + 7;
const int MOD2 = MOD + 2; //1007681537;
const int INF = (int) 1e9;
const ll LINF = (ll) 1e18;
const ld PI = acos((ld) - 1);
const ld EPS = 1e-9;
inline ll gcd(ll a, ll b) {ll r; while (b) {r = a % b; a = b; b = r;} return a;}
inline ll lcm(ll a, ll b) {return a / gcd(a, b) * b;}
inline ll fpow(ll n, ll k, int p = MOD) {ll r = 1; for (; k; k >>= 1) {if (k & 1) r = r * n % p; n = n * n % p;} return r;}
template<class T> inline int chkmin(T& a, const T& val) {return val < a ? a = val, 1 : 0;}
template<class T> inline int chkmax(T& a, const T& val) {return a < val ? a = val, 1 : 0;}
inline ll isqrt(ll k) {ll r = sqrt(k) + 1; while (r * r > k) r--; return r;}
inline ll icbrt(ll k) {ll r = cbrt(k) + 1; while (r * r * r > k) r--; return r;}
inline void addmod(int& a, int val, int p = MOD) {if ((a = (a + val)) >= p) a -= p;}
inline void submod(int& a, int val, int p = MOD) {if ((a = (a - val)) < 0) a += p;}
inline int mult(int a, int b, int p = MOD) {return (ll) a * b % p;}
inline int inv(int a, int p = MOD) {return fpow(a, p - 2, p);}
inline int sign(ld x) {return x < -EPS ? -1 : x > +EPS;}
inline int sign(ld x, ld y) {return sign(x - y);}
int modulo(int a, int b) { return (a % b + b) % b; }
#define db(x) cerr << #x << " = " << (x) << " ";
#define endln cerr << "\n";

int main()
{
	IOS;
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	int t;
	cin >> t;
	while (t--) {
		ll n, m;
		cin >> n >> m;
		vector<vi> a(n, vi(m)), b(n, vi(m));
		f(i, 0, n - 1) {
			f(j, 0, m - 1) {
				cin >> a[i][j];
			}
		}
		f(i, 0, n - 1) {
			f(j, 0, m - 1) {
				if (j + 1 < m) {
					if (a[i][j + 1] == a[i][j]) {
						a[i][j + 1]++;
					}
				}
				if (i + 1 < n) {
					if (a[i + 1][j] == a[i][j]) {
						a[i + 1][j]++;
					}

				}
				if (j > 0) {
					if (a[i][j - 1] == a[i][j]) {
						a[i][j - 1]++;
					}
				}
				if (i > 0) {
					if (a[i - 1][j] == a[i][j]) {
						a[i - 1][j]++;
					}

				}
			}
		}
		f(i, 0, n - 1) {
			f(j, 0, m - 1) {
				cout << a[i][j] << " ";
			}
			cout <<  "\n";
		}
	}
	// read the stuff at the bottom
	return 0;
}
/* stuff you should look for
	* int overflow, array bounds
	* special cases (n=1?)
	* do smth instead of nothing and stay organized
	* WRITE STUFF DOWN
	* use int when constraints limits are tight
	* Time taken : global variable < pass by refernce < pass by value
	* It takes significant amt. of time in pass by value
	* Avoid Using endl
*/


#include <bits/stdc++.h>
using namespace std;

#define ms(s, n) memset(s, n, sizeof(s))
#define f(i, a, b) for (int i = (a); i <=(b); i++)
#define FORd(i, a, b) for (int i = (a) - 1; i >= (b); i--)
#define FORall(it, a) for (__typeof((a).begin()) it = (a).begin(); it != (a).end(); it++)
#define sz(a) int((a).size())
#define present(t, x) (t.find(x) != t.end())
#define all(a) (a).begin(), (a).end()
#define uni(a) (a).erase(unique(all(a)), (a).end())
#define pb push_back
#define pf push_front
#define mp make_pair
#define fi first
#define se second
#define prec(n) fixed<<setprecision(n)
#define bit(n, i) (((n) >> (i)) & 1)
#define bitcount(n) __builtin_popcountll(n)
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int, int> pi;
typedef vector<ll> vi;
typedef vector<pi> vii;
const int MOD = (int) 1e9 + 7;
const int MOD2 = MOD + 2; //1007681537;
const int INF = (int) 1e9;
const ll LINF = (ll) 1e18;
const ld PI = acos((ld) - 1);
const ld EPS = 1e-9;
inline ll gcd(ll a, ll b) {ll r; while (b) {r = a % b; a = b; b = r;} return a;}
inline ll lcm(ll a, ll b) {return a / gcd(a, b) * b;}
inline ll fpow(ll n, ll k, int p = MOD) {ll r = 1; for (; k; k >>= 1) {if (k & 1) r = r * n % p; n = n * n % p;} return r;}
template<class T> inline int chkmin(T& a, const T& val) {return val < a ? a = val, 1 : 0;}
template<class T> inline int chkmax(T& a, const T& val) {return a < val ? a = val, 1 : 0;}
inline ll isqrt(ll k) {ll r = sqrt(k) + 1; while (r * r > k) r--; return r;}
inline ll icbrt(ll k) {ll r = cbrt(k) + 1; while (r * r * r > k) r--; return r;}
inline void addmod(int& a, int val, int p = MOD) {if ((a = (a + val)) >= p) a -= p;}
inline void submod(int& a, int val, int p = MOD) {if ((a = (a - val)) < 0) a += p;}
inline int mult(int a, int b, int p = MOD) {return (ll) a * b % p;}
inline int inv(int a, int p = MOD) {return fpow(a, p - 2, p);}
inline int sign(ld x) {return x < -EPS ? -1 : x > +EPS;}
inline int sign(ld x, ld y) {return sign(x - y);}
int modulo(int a, int b) { return (a % b + b) % b; }
#define db(x) cerr << #x << " = " << (x) << " ";
#define endln cerr << "\n";

vector<vi>a;
ll n, m;
vector<vector<bool>>vis;
vi dx = {0, 0, 1, -1}, dy = {1, -1, 0, 0};
void dfs(ll i, ll j, ll col) {
	if (i < 0 || i >= n || j < 0 || j >= m || vis[i][j]) {
		return ;
	}
	vis[i][j] = 1;
	if (a[i][j] % 2 != col) {
		a[i][j]++;
	}
	f(k, 0, 3) {
		ll x = i + dx[k];
		ll y = j + dy[k];
		dfs(x, y, col ^ 1);
	}
}
int main()
{
	IOS;
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	int t;
	cin >> t;
	while (t--) {
		cin >> n >> m;
		a = vector<vi>(n, vi(m));
		f(i, 0, n - 1) {
			f(j, 0, m - 1) {
				cin >> a[i][j];
			}
		}
		vis = vector<vector<bool>>(n, vector<bool>(m, 0));
		dfs(0, 0, 0);
		f(i, 0, n - 1) {
			f(j, 0, m - 1) {
				cout << a[i][j] << " ";
			}
			cout << "\n";
		}
	}
// read the stuff at the bottom
	return 0;
}
/* stuff you should look for
	* int overflow, array bounds
	* special cases (n=1?)
	* do smth instead of nothing and stay organized
	* WRITE STUFF DOWN
	* use int when constraints limits are tight
	* Time taken : global variable < pass by refernce < pass by value
	* It takes significant amt. of time in pass by value
	* Avoid Using endl
*/


#include <bits/stdc++.h>
using namespace std;

#define ms(s, n) memset(s, n, sizeof(s))
#define f(i, a, b) for (int i = (a); i <=(b); i++)
#define FORd(i, a, b) for (int i = (a) - 1; i >= (b); i--)
#define FORall(it, a) for (__typeof((a).begin()) it = (a).begin(); it != (a).end(); it++)
#define sz(a) int((a).size())
#define present(t, x) (t.find(x) != t.end())
#define all(a) (a).begin(), (a).end()
#define uni(a) (a).erase(unique(all(a)), (a).end())
#define pb push_back
#define pf push_front
#define mp make_pair
#define fi first
#define se second
#define prec(n) fixed<<setprecision(n)
#define bit(n, i) (((n) >> (i)) & 1)
#define bitcount(n) __builtin_popcountll(n)
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int, int> pi;
typedef vector<ll> vi;
typedef vector<pi> vii;
const int MOD = (int) 1e9 + 7;
const int MOD2 = MOD + 2; //1007681537;
const int INF = (int) 1e9;
const ll LINF = (ll) 1e18;
const ld PI = acos((ld) - 1);
const ld EPS = 1e-9;
inline ll gcd(ll a, ll b) {ll r; while (b) {r = a % b; a = b; b = r;} return a;}
inline ll lcm(ll a, ll b) {return a / gcd(a, b) * b;}
inline ll fpow(ll n, ll k, int p = MOD) {ll r = 1; for (; k; k >>= 1) {if (k & 1) r = r * n % p; n = n * n % p;} return r;}
template<class T> inline int chkmin(T& a, const T& val) {return val < a ? a = val, 1 : 0;}
template<class T> inline int chkmax(T& a, const T& val) {return a < val ? a = val, 1 : 0;}
inline ll isqrt(ll k) {ll r = sqrt(k) + 1; while (r * r > k) r--; return r;}
inline ll icbrt(ll k) {ll r = cbrt(k) + 1; while (r * r * r > k) r--; return r;}
inline void addmod(int& a, int val, int p = MOD) {if ((a = (a + val)) >= p) a -= p;}
inline void submod(int& a, int val, int p = MOD) {if ((a = (a - val)) < 0) a += p;}
inline int mult(int a, int b, int p = MOD) {return (ll) a * b % p;}
inline int inv(int a, int p = MOD) {return fpow(a, p - 2, p);}
inline int sign(ld x) {return x < -EPS ? -1 : x > +EPS;}
inline int sign(ld x, ld y) {return sign(x - y);}
int modulo(int a, int b) { return (a % b + b) % b; }
#define db(x) cerr << #x << " = " << (x) << " ";
#define endln cerr << "\n";

vector<vi>a;
ll n, m;
vector<vector<bool>>vis, inc;
bool valid(ll i, ll j) {
	if (i + 1 < n && a[i][j] + 1 == a[i + 1][j] && inc[i + 1][j]) {
		return 0;
	}
	if (j + 1 < m && a[i][j] + 1 == a[i][j + 1] && inc[i][j + 1]) {
		return 0;
	}
	if (i > 0 && a[i][j] + 1 == a[i - 1][j] && inc[i - 1][j]) {
		return 0;
	}
	if (j > 0 && a[i][j] + 1 == a[i][j - 1] && inc[i][j - 1]) {
		return 0;
	}
	return 1;
}
void dfs(ll i, ll j) {
	if (i < 0 || i >= n || j < 0 || j >= m) {
		return ;
	}
	//vis[i][j] = 1;
	//cout << i << " " << j << ": \n";
	bool f = 1;
	if (j + 1 < m && a[i][j] == a[i][j + 1]) {
		if (f && valid(i, j) && !inc[i][j]) {
			//cout << "f " << i << " " << j + 1 << "\n";
			a[i][j]++;
			inc[i][j] = 1;
			f = 0;
			dfs(i, j);
		}
		else if (valid(i, j + 1) && !inc[i][j + 1]) {
			//cout << i << " " << j + 1 << "\n";
			a[i][j + 1]++;
			inc[i][j + 1] = 1;
			dfs(i, j + 1);
		}
	}
	if (j > 0 && a[i][j] == a[i][j - 1]) {
		if (f && valid(i, j) && !inc[i][j]) {
			//cout << "f " << i << " " << j - 1 << "\n";
			a[i][j]++; inc[i][j] = 1; f = 0;
			dfs(i, j);
		}
		else if (valid(i, j - 1) && !inc[i][j - 1]) {
			//cout <<  i << " " << j - 1 << "\n";
			a[i][j - 1]++;
			inc[i][j - 1] = 1;
			dfs(i, j - 1);
		}
	}
	if (i + 1 < n && a[i][j] == a[i + 1][j]) {
		if (f && valid(i, j) && !inc[i][j]) {
			//cout << "f " << i + 1 << " " << j  << "\n";
			a[i][j]++; inc[i][j] = 1; f = 0;
			dfs(i, j);
		}
		else  if (valid(i + 1, j) && !inc[i + 1][j]) {
			//cout <<  i + 1 << " " << j  << "\n";
			a[i + 1][j]++;
			inc[i + 1][j] = 1;
			dfs(i + 1, j);
		}
	}
	if (i > 0 && a[i][j] == a[i - 1][j]) {
		if (f && valid(i, j) && !inc[i][j]) {
			//cout << "f " << i - 1 << " " << j << "\n";
			a[i][j]++; inc[i][j] = 1; f = 0;
			dfs(i, j);
		}
		else  if (valid(i - 1, j) && !inc[i - 1][j]) {
			//cout <<  i - 1 << " " << j  << "\n";
			a[i - 1][j]++;
			inc[i - 1][j] = 1;
			dfs(i - 1, j);
		}
	}
}
int main()
{
	IOS;
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	int t;
	cin >> t;
	while (t--) {
		cin >> n >> m;
		vector<vi> b(n, vi(m));
		a = vector<vi>(n, vi(m));
		vis = vector<vector<bool>>(n, vector<bool>(m, 0));
		inc = vector<vector<bool>>(n, vector<bool>(m, 0));
		f(i, 0, n - 1) {
			f(j, 0, m - 1) {
				cin >> a[i][j];
			}
		}
		//dfs(0, 0);
		f(i, 0, n - 1) {
			f(j, 0, m - 1) {
				if (vis[i][j])
					continue;
				dfs(i, j);
				// f(i, 0, n - 1) {
				// 	f(j, 0, m - 1) {
				// 		cout << a[i][j] << " ";
				// 	}
				// 	cout <<  "\n";
				// }
			}
		}
		f(i, 0, n - 1) {
			f(j, 0, m - 1) {
				cout << a[i][j] << " ";
			}
			cout <<  "\n";
		}
	}
// read the stuff at the bottom
	return 0;
}
/* stuff you should look for
	* int overflow, array bounds
	* special cases (n=1?)
	* do smth instead of nothing and stay organized
	* WRITE STUFF DOWN
	* use int when constraints limits are tight
	* Time taken : global variable < pass by refernce < pass by value
	* It takes significant amt. of time in pass by value
	* Avoid Using endl
*/


#include <bits/stdc++.h>
using namespace std;

#define ms(s, n) memset(s, n, sizeof(s))
#define f(i, a, b) for (int i = (a); i <=(b); i++)
#define FORd(i, a, b) for (int i = (a) - 1; i >= (b); i--)
#define FORall(it, a) for (__typeof((a).begin()) it = (a).begin(); it != (a).end(); it++)
#define sz(a) int((a).size())
#define present(t, x) (t.find(x) != t.end())
#define all(a) (a).begin(), (a).end()
#define uni(a) (a).erase(unique(all(a)), (a).end())
#define pb push_back
#define pf push_front
#define mp make_pair
#define fi first
#define se second
#define prec(n) fixed<<setprecision(n)
#define bit(n, i) (((n) >> (i)) & 1)
#define bitcount(n) __builtin_popcountll(n)
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int, int> pi;
typedef vector<ll> vi;
typedef vector<pi> vii;
const int MOD = (int) 1e9 + 7;
const int MOD2 = MOD + 2; //1007681537;
const int INF = (int) 1e9;
const ll LINF = (ll) 1e18;
const ld PI = acos((ld) - 1);
const ld EPS = 1e-9;
inline ll gcd(ll a, ll b) {ll r; while (b) {r = a % b; a = b; b = r;} return a;}
inline ll lcm(ll a, ll b) {return a / gcd(a, b) * b;}
inline ll fpow(ll n, ll k, int p = MOD) {ll r = 1; for (; k; k >>= 1) {if (k & 1) r = r * n % p; n = n * n % p;} return r;}
template<class T> inline int chkmin(T& a, const T& val) {return val < a ? a = val, 1 : 0;}
template<class T> inline int chkmax(T& a, const T& val) {return a < val ? a = val, 1 : 0;}
inline ll isqrt(ll k) {ll r = sqrt(k) + 1; while (r * r > k) r--; return r;}
inline ll icbrt(ll k) {ll r = cbrt(k) + 1; while (r * r * r > k) r--; return r;}
inline void addmod(int& a, int val, int p = MOD) {if ((a = (a + val)) >= p) a -= p;}
inline void submod(int& a, int val, int p = MOD) {if ((a = (a - val)) < 0) a += p;}
inline int mult(int a, int b, int p = MOD) {return (ll) a * b % p;}
inline int inv(int a, int p = MOD) {return fpow(a, p - 2, p);}
inline int sign(ld x) {return x < -EPS ? -1 : x > +EPS;}
inline int sign(ld x, ld y) {return sign(x - y);}
int modulo(int a, int b) { return (a % b + b) % b; }
#define db(x) cerr << #x << " = " << (x) << " ";
#define endln cerr << "\n";

vector<vi>a;
ll n, m;
vector<vector<bool>>vis, inc;
bool valid(ll i, ll j) {
	if (i + 1 < n && a[i][j] + 1 == a[i + 1][j] && inc[i + 1][j]) {
		return 0;
	}
	if (j + 1 < m && a[i][j] + 1 == a[i][j + 1] && inc[i][j + 1]) {
		return 0;
	}
	if (i > 0 && a[i][j] + 1 == a[i - 1][j] && inc[i - 1][j]) {
		return 0;
	}
	if (j > 0 && a[i][j] + 1 == a[i][j - 1] && inc[i][j - 1]) {
		return 0;
	}
	return 1;
}
void dfs(ll i, ll j) {
	if (i < 0 || i >= n || j < 0 || j >= m || vis[i][j]) {
		return ;
	}
	vis[i][j] = 1;
	//cout << i << " " << j << ": \n";
	bool f = 1;
	if (j + 1 < m && a[i][j] == a[i][j + 1]) {
		if (f && valid(i, j) && !inc[i][j]) {
			//cout << "f " << i << " " << j + 1 << "\n";
			a[i][j]++;
			inc[i][j] = 1;
			f = 0;
		}
		else {
			//cout << i << " " << j + 1 << "\n";
			a[i][j + 1]++;
			inc[i][j + 1] = 1;
			dfs(i, j + 1);
		}
	}
	if (j > 0 && a[i][j] == a[i][j - 1]) {
		if (f && valid(i, j) && !inc[i][j]) {
			//cout << "f " << i << " " << j - 1 << "\n";
			a[i][j]++; inc[i][j] = 1; f = 0;
		}
		else {
			//cout <<  i << " " << j - 1 << "\n";
			a[i][j - 1]++;
			inc[i][j - 1] = 1;
			dfs(i, j - 1);
		}
	}
	if (i + 1 < n && a[i][j] == a[i + 1][j]) {
		if (f && valid(i, j) && !inc[i][j]) {
			//cout << "f " << i + 1 << " " << j  << "\n";
			a[i][j]++; inc[i][j] = 1; f = 0;
		}
		else {
			//cout <<  i + 1 << " " << j  << "\n";
			a[i + 1][j]++;
			inc[i + 1][j] = 1;
			dfs(i + 1, j);
		}
	}
	if (i > 0 && a[i][j] == a[i - 1][j]) {
		if (f && valid(i, j) && !inc[i][j]) {
			//cout << "f " << i - 1 << " " << j << "\n";
			a[i][j]++; inc[i][j] = 1; f = 0;
		}
		else {
			//cout <<  i - 1 << " " << j  << "\n";
			a[i - 1][j]++;
			inc[i - 1][j] = 1;
			dfs(i - 1, j);
		}
	}
}
int main()
{
	IOS;
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	int t;
	cin >> t;
	while (t--) {
		cin >> n >> m;
		vector<vi> b(n, vi(m));
		a = vector<vi>(n, vi(m));
		vis = vector<vector<bool>>(n, vector<bool>(m, 0));
		inc = vector<vector<bool>>(n, vector<bool>(m, 0));
		f(i, 0, n - 1) {
			f(j, 0, m - 1) {
				cin >> a[i][j];
			}
		}
		//dfs(0, 0);
		f(i, 0, n - 1) {
			f(j, 0, m - 1) {
				if (vis[i][j])
					continue;
				dfs(i, j);
				// f(i, 0, n - 1) {
				// 	f(j, 0, m - 1) {
				// 		cout << a[i][j] << " ";
				// 	}
				// 	cout <<  "\n";
				// }
			}
		}
		f(i, 0, n - 1) {
			f(j, 0, m - 1) {
				cout << a[i][j] << " ";
			}
			cout <<  "\n";
		}
	}
// read the stuff at the bottom
	return 0;
}
/* stuff you should look for
	* int overflow, array bounds
	* special cases (n=1?)
	* do smth instead of nothing and stay organized
	* WRITE STUFF DOWN
	* use int when constraints limits are tight
	* Time taken : global variable < pass by refernce < pass by value
	* It takes significant amt. of time in pass by value
	* Avoid Using endl
*/


#include<bits/stdc++.h>
using namespace std;

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

    while(t--){
        int n,m;

        cin>>n>>m;
        int arr[n][m];
        for(int i=0;i<n;i++){
            for(int j=0;j<m;j++){
                cin>>arr[i][j];
            }
        }
        int flag=1;
        for(int i=0;i<n;i++){
            for(int j=0;j<m;j++){
                if(flag==1){
                    if(arr[i][j]%2!=0){arr[i][j]+=1;
                        flag=0;

                    }

                    else flag=1;
                }
                else if(flag==0){
                    if(arr[i][j]%2==0){arr[i][j]+=1;
                        flag=1;

                    }
                    else flag=0;

                }

            }
        }
        for(int i=0;i<n;i++){
            for(int j=0;j<m;j++){
                cout<<arr[i][j]<<" ";
            }
            cout<<endl;
        }
    }
    return 0;

}


#include<bits/stdc++.h>
using namespace std;

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

    while(t--){
        int n,m,temp;

        cin>>n>>m;

        for(int i=0;i<n;i++){
            for(int j=0;j<m;j++){
                cin>>temp;
                if((i+j)%2!=temp%2)cout<<temp+1;
                else cout<<temp;
                cout<<" ";
            }
        }

    return 0;

}
}


#include<bits/stdc++.h>
using namespace std;

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

    while(t--){
        int n,m,temp;

        cin>>n>>m;

        for(int i=1;i<=n;i++){
            for(int j=1;j<=m;j++){
                cin>>temp;
                if((i+j)%2!=temp%2)cout<<temp+1;
                else cout<<temp;
                cout<<" ";
            }
            cout<<"\n";
        }

}
return 0;
}


#include<bits/stdc++.h>
using namespace std;

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

    while(t--){
        int n,m,temp;

        cin>>n>>m;

        for(int i=0;i<n;i++){
            for(int j=0;j<m;j++){
                cin>>temp;
                if((i+j)%2!=temp%2)cout<<temp+1;
                else cout<<temp;
                cout<<" ";
            }
            cout<<endl;
        }

    return 0;

}
}


#include<bits/stdc++.h>
using namespace std;

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

    while(t--){
        int n,m,temp;

        cin>>n>>m;

        for(int i=1;i=<n;i++){
            for(int j=1;j=<m;j++){
                cin>>temp;
                if((i+j)%2!=temp%2)cout<<temp+1;
                else cout<<temp;
                cout<<" ";
            }
            cout<<"\n";
        }

    return 0;

}
}