#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define ull unsigned long long
#define pb push_back
#define pp pop_back
#define pi pair<ll,ll>
#define pii pair<int,int>
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    ll n,i,j,k,l,m,b,t,sum,sum1,flag,max1,min1,tmp;
    cin>>t;
    while(t--){
        cin>>n>>m;
        ll a[101][101];
        for(i=1;i<=n;i++){
            for(j=1;j<=m;j++){
                cin>>a[i][j];
            }
        }
        flag=0;
        if(a[1][1]%2==1){
            for(j=1;j<=m;j++){
                if(j%2==1){
                    if(a[1][j]%2==0){
                        a[i][j]+=1;
                    }
                }else{
                    if(a[1][j]%2==1){
                        a[1][j]+=1;
                    }
                }
            }
        }else{
            for(j=1;j<=m;j++){
                if(j%2==1){
                    if(a[i][j]%2==1){
                        a[i][j]+=1;
                    }
                }else{
                    if(a[i][j]%2==0){
                        a[i][j]+=1;
                    }
                }
            }
        }
        for(i=2;i<=n;i++){
            if(a[i-1][1]%2==1){
                for(j=1;j<=m;j++){
                    if(j%2==1){
                        if(a[i][j]%2==1){
                            a[i][j]+=1;
                        }
                    }else{
                        if(a[i][j]%2==0){
                            a[i][j]+=1;
                        }
                    }
                }
            }else{
                for(j=1;j<=m;j++){
                    if(j%2==1){
                        if(a[i][j]%2==0){
                            a[i][j]+=1;
                        }
                    }else{
                        if(a[i][j]%2==0){
                            a[i][j]+=1;
                        }
                    }
                }
            }
        }
//        for(i=1;i<=n;i++){
//           if(a[i][1]%2==1){
//            for(j=2;j<=m;j++){
//                if(j%2==0){
//                    if(a[i][j]%2==1){
//                        a[i][j]+=1;
//                    }
//                }else{
//                    if(a[i][j]%2==0){
//                        a[i][j]+=1;
//                    }
//                }
//            }
//           }else{
//               for(j=2;j<=m;j++){
//                if(j%2==1){
//                    if(a[i][j]%2==1){
//                        a[i][j]+=1;
//                    }
//                }else{
//                    if(a[i][j]%2==0){
//                        a[i][j]+=1;
//                    }
//                }
//            }
//           }
//        }
//        for(i=1;i<=n;i++){
//            for(j=2;j<=m;j++){
//                flag=0;
//                if(a[i][j]==a[i][j-1]){
//                    a[i][j]+=1;
//                    flag=1;
//                }
//                if(i!=1 and flag==0){
//                    if(a[i-1][j]==a[i][j]){
//                        a[i][j]+=1;
//                        flag=1;
//                    }
//                }
//                if(abs(j-i)==1 and flag==0 and abs(a[i][j]-a[j][i])==1){
//                    a[i][j]+=1;
//                    flag=1;
//                }
//                if(i+1<=n and j+1<=m and flag==0 and abs(a[i][j]-a[i+1][j+1])==1){
//                    a[i][j]+=1;
//                    flag=1;
//                }
//                if(i+1<=n and j-1>=1 and j-1<=m and flag==0 and abs(a[i][j]-a[i+1][j-1])==1){
//                    a[i][j]+=1;
//                }
//            }
//        }
//        cout<<"out::\n";
        for(i=1;i<=n;i++){
            for(j=1;j<=m;j++){
                cout<<a[i][j]<<" ";
            }cout<<endl;
        }
    }

}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define ull unsigned long long
#define pb push_back
#define pp pop_back
#define pi pair<ll,ll>
#define pii pair<int,int>
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    ll n,i,j,k,l,m,b,t,sum,sum1,flag,max1,min1,tmp;
    cin>>t;
    while(t--){
        cin>>n>>m;
        ll a[n+1][m+1];
        for(i=1;i<=n;i++){
            for(j=1;j<=m;j++){
                cin>>a[i][j];
            }
        }
        for(i=1;i<=n;i++){
            for(j=2;j<=m;j++){
                flag=0;
                if(a[i][j]==a[i][j-1]){
                    a[i][j]+=1;
                    flag=1;
                }
                if(i!=1 and flag==0){
                    if(a[i-1][j]==a[i][j]){
                        a[i][j]+=1;
                    }
                }
                if((j-i)==1 and flag==0 and abs(a[i][j]-a[j][i])==1){
                    a[i][j]+=1;
                }
            }
        }
//        cout<<"out::\n";
        for(i=1;i<=n;i++){
            for(j=1;j<=m;j++){
                cout<<a[i][j]<<" ";
            }cout<<endl;
        }
    }

}


#include<bits/stdc++.h>
#define        u64             uint64_t
#define        ll              long long
#define        endl            "\n"
#define        PI              acos(-1)
#define        fi              first
#define        si              second
#define        mkp             make_pair
#define        pb              push_back
#define        set0(arr)       memset(arr, 0, sizeof(arr))
#define        setinf(arr)     memset(arr, 126, sizeof(arr))
#define        all(x)          (x).begin(),(x).end()
#define        sz(v)           ((ll)(v).size())
#define        IOS             ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
using namespace std;
using          pll        =      pair<ll, ll> ;
using          vl         =      vector<ll> ;
using          vpll       =      vector<pll> ;
using          mll        =      map<ll, ll> ;
using          mcl        =      map<char, ll> ;
using          msl        =      map<string,ll> ;
using          sl         =      set<ll> ;
using          sc         =      set<char> ;
using          dl         =      deque<ll> ;
const int N = 1e6+5 ;

ll      mod = 1e9+7 ;
vl      adj[N] ;
vpll    adjc[N] ;
ll      vis[N] ;
ll      arr[N] ;

ll muld(ll a,ll b)
{
       return (((a%mod)*(b%mod))%mod);
}
ll sumd(ll a,ll b)
{
       return (((a%mod)+(b%mod))%mod);
}
ll subd(ll a,ll b)
{
       return (((a%mod)-(b%mod)+mod)%mod);
}

int main()
{
    IOS;
    ll a, b, c, d, n, m, p, x, y, z, i, j, k, f = 0, tc, cnt = 0, sum = 0, mul = 1, mi = 1e18, ma = -1e18, cs;
    string   str ;
    char     ch ;
    double   db ;
    ll       l, r ;
    //code

    cin>>tc;
    for(cs=1;cs<=tc;cs++)
    {
        cin>>n>>m;
        ll M[n][m];
        for(i=0;i<n;i++)
        {
               for(j=0;j<m;j++)
               {
                      cin>>M[i][j];
               }
        }

        for(i=0;i<n;i++)
        {
               for(j=0;j<m;j++)
               {
                     x=M[i][j];
                     if(i-1>=0&&x==M[i-1][j])
                     {
                            f=0;
                           if(i-1>=0&&x+1==M[i-1][j]) f=1;
                           else if(j-1>=0&&x+1==M[i-1][j]) f=1;
                           else if(i+1<n&&x+1==M[i+1][j]) f=1;
                           else if(j+1<m&&x+1==M[i][j+1]) f=1;
                           if(f==0){
                               M[i][j]=x+1;
                               continue;
                           }

                     }
                     if(j-1>=0&&x==M[i][j-1])
                     {
                           f=0;
                           if(i-1>=0&&x+1==M[i-1][j]) f=1;
                           else if(j-1>=0&&x+1==M[i-1][j]) f=1;
                           else if(i+1<n&&x+1==M[i+1][j]) f=1;
                           else if(j+1<m&&x+1==M[i][j+1]) f=1;
                           if(f==0){
                               M[i][j]=x+1;
                               continue;
                           }
                     }
                     if(i+1<n&&x==M[i+1][j])
                     {
                             f=0;
                           if(i-1>=0&&x+1==M[i-1][j]) f=1;
                           else if(j-1>=0&&x+1==M[i-1][j]) f=1;
                           else if(i+1<n&&x+1==M[i+1][j]) f=1;
                           else if(j+1<m&&x+1==M[i][j+1]) f=1;
                           if(f==0){
                               M[i][j]=x+1;
                               continue;
                           }
                     }
                     if(j+1<m&&x==M[i][j+1])
                     {
                             f=0;
                           if(i-1>=0&&x+1==M[i-1][j]) f=1;
                           else if(j-1>=0&&x+1==M[i-1][j]) f=1;
                           else if(i+1<n&&x+1==M[i+1][j]) f=1;
                           else if(j+1<m&&x+1==M[i][j+1]) f=1;
                           if(f==0){
                               M[i][j]=x+1;
                               continue;
                           }
                     }

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

    }

    //code
    return 0;
}


#include<bits/stdc++.h>
#define        u64             uint64_t
#define        ll              long long
#define        endl            "\n"
#define        PI              acos(-1)
#define        fi              first
#define        si              second
#define        mkp             make_pair
#define        pb              push_back
#define        set0(arr)       memset(arr, 0, sizeof(arr))
#define        setinf(arr)     memset(arr, 126, sizeof(arr))
#define        all(x)          (x).begin(),(x).end()
#define        sz(v)           ((ll)(v).size())
#define        IOS             ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
using namespace std;
using          pll        =      pair<ll, ll> ;
using          vl         =      vector<ll> ;
using          vpll       =      vector<pll> ;
using          mll        =      map<ll, ll> ;
using          mcl        =      map<char, ll> ;
using          msl        =      map<string,ll> ;
using          sl         =      set<ll> ;
using          sc         =      set<char> ;
using          dl         =      deque<ll> ;
const int N = 1e6+5 ;

ll      mod = 1e9+7 ;
vl      adj[N] ;
vpll    adjc[N] ;
ll      vis[N] ;
ll      arr[N] ;

ll muld(ll a,ll b)
{
       return (((a%mod)*(b%mod))%mod);
}
ll sumd(ll a,ll b)
{
       return (((a%mod)+(b%mod))%mod);
}
ll subd(ll a,ll b)
{
       return (((a%mod)-(b%mod)+mod)%mod);
}

int main()
{
    IOS;
    ll a, b, c, d, n, m, p, x, y, z, i, j, k, f = 0, tc, cnt = 0, sum = 0, mul = 1, mi = 1e18, ma = -1e18, cs;
    string   str ;
    char     ch ;
    double   db ;
    ll       l, r ;
    //code

    cin>>tc;
    for(cs=1;cs<=tc;cs++)
    {
        cin>>n>>m;
        ll M[n][m];
        for(i=0;i<n;i++)
        {
               for(j=0;j<m;j++)
               {
                      cin>>M[i][j];
               }
        }

        for(i=0;i<n;i++)
        {
               for(j=0;j<m;j++)
               {
                     x=M[i][j];
                     if(i-1>=0&&x==M[i-1][j])
                     {
                           f=0;

                           if(i+1<n&&x+1==M[i+1][j]) f=1;
                           else if(j+1<m&&x+1==M[i][j+1]) f=1;
                           if(f==0){
                               M[i][j]=x+1;
                           }
                     }
                     else if(j-1>=0&&x==M[i][j-1])
                     {
                           f=0;

                           if(i+1<n&&x+1==M[i+1][j]) f=1;
                           else if(j+1<m&&x+1==M[i][j+1]) f=1;
                           if(f==0){
                               M[i][j]=x+1;
                           }
                     }
                     else if(i+1<n&&x==M[i+1][j])
                     {
                            f=0;

                           if(i+1<n&&x+1==M[i+1][j]) f=1;
                           else if(j+1<m&&x+1==M[i][j+1]) f=1;
                           if(f==0){
                               M[i][j]=x+1;
                           }
                     }
                     else if(j+1<m&&x==M[i][j+1])
                     {
                             f=0;

                           if(i+1<n&&x+1==M[i+1][j]) f=1;
                           else if(j+1<m&&x+1==M[i][j+1]) f=1;
                           if(f==0){
                               M[i][j]=x+1;
                           }
                     }

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

    }

    //code
    return 0;
}


#include<bits/stdc++.h>
#define        u64             uint64_t
#define        ll              long long
#define        endl            "\n"
#define        PI              acos(-1)
#define        fi              first
#define        si              second
#define        mkp             make_pair
#define        pb              push_back
#define        set0(arr)       memset(arr, 0, sizeof(arr))
#define        setinf(arr)     memset(arr, 126, sizeof(arr))
#define        all(x)          (x).begin(),(x).end()
#define        sz(v)           ((ll)(v).size())
#define        IOS             ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
using namespace std;
using          pll        =      pair<ll, ll> ;
using          vl         =      vector<ll> ;
using          vpll       =      vector<pll> ;
using          mll        =      map<ll, ll> ;
using          mcl        =      map<char, ll> ;
using          msl        =      map<string,ll> ;
using          sl         =      set<ll> ;
using          sc         =      set<char> ;
using          dl         =      deque<ll> ;
const int N = 1e6+5 ;

ll      mod = 1e9+7 ;
vl      adj[N] ;
vpll    adjc[N] ;
ll      vis[N] ;
ll      arr[N] ;

ll muld(ll a,ll b)
{
       return (((a%mod)*(b%mod))%mod);
}
ll sumd(ll a,ll b)
{
       return (((a%mod)+(b%mod))%mod);
}
ll subd(ll a,ll b)
{
       return (((a%mod)-(b%mod)+mod)%mod);
}

int main()
{
    IOS;
    ll a, b, c, d, n, m, p, x, y, z, i, j, k, f = 0, tc, cnt = 0, sum = 0, mul = 1, mi = 1e18, ma = -1e18, cs;
    string   str ;
    char     ch ;
    double   db ;
    ll       l, r ;
    //code

    cin>>tc;
    for(cs=1;cs<=tc;cs++)
    {
        cin>>n>>m;
        ll M[n][m];
        for(i=0;i<n;i++)
        {
               for(j=0;j<m;j++)
               {
                      cin>>M[i][j];
               }
        }

        for(i=0;i<n;i++)
        {
               for(j=0;j<m;j++)
               {
                     x=M[i][j];
                     if(i-1>=0&&x==M[i-1][j])
                     {
                            f=0;
                           if(i-1>=0&&x+1==M[i-1][j]) f=1;
                           else if(j-1>=0&&x+1==M[i][j-1]) f=1;
                           else if(i+1<n&&x+1==M[i+1][j]) f=1;
                           else if(j+1<m&&x+1==M[i][j+1]) f=1;
                           if(f==0){
                               M[i][j]=x+1;
                           }
                     }
                     else if(j-1>=0&&x==M[i][j-1])
                     {
                           f=0;
                           if(i-1>=0&&x+1==M[i-1][j]) f=1;
                           else if(j-1>=0&&x+1==M[i][j-1]) f=1;
                           else if(i+1<n&&x+1==M[i+1][j]) f=1;
                           else if(j+1<m&&x+1==M[i][j+1]) f=1;
                           if(f==0){
                               M[i][j]=x+1;
                           }
                     }
                     else if(i+1<n&&x==M[i+1][j])
                     {
                             f=0;
                           if(i-1>=0&&x+1==M[i-1][j]) f=1;
                           else if(j-1>=0&&x+1==M[i][j-1]) f=1;
                           else if(i+1<n&&x+1==M[i+1][j]) f=1;
                           else if(j+1<m&&x+1==M[i][j+1]) f=1;
                           if(f==0){
                               M[i][j]=x+1;
                           }
                     }
                     else if(j+1<m&&x==M[i][j+1])
                     {
                             f=0;
                           if(i-1>=0&&x+1==M[i-1][j]) f=1;
                           else if(j-1>=0&&x+1==M[i][j-1]) f=1;
                           else if(i+1<n&&x+1==M[i+1][j]) f=1;
                           else if(j+1<m&&x+1==M[i][j+1]) f=1;
                           if(f==0){
                               M[i][j]=x+1;
                           }
                     }

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

    }

    //code
    return 0;
}


#include<bits/stdc++.h>
#define        u64             uint64_t
#define        ll              long long
#define        endl            "\n"
#define        PI              acos(-1)
#define        fi              first
#define        si              second
#define        mkp             make_pair
#define        pb              push_back
#define        set0(arr)       memset(arr, 0, sizeof(arr))
#define        setinf(arr)     memset(arr, 126, sizeof(arr))
#define        all(x)          (x).begin(),(x).end()
#define        sz(v)           ((ll)(v).size())
#define        IOS             ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
using namespace std;
using          pll        =      pair<ll, ll> ;
using          vl         =      vector<ll> ;
using          vpll       =      vector<pll> ;
using          mll        =      map<ll, ll> ;
using          mcl        =      map<char, ll> ;
using          msl        =      map<string,ll> ;
using          sl         =      set<ll> ;
using          sc         =      set<char> ;
using          dl         =      deque<ll> ;
const int N = 1e6+5 ;

ll      mod = 1e9+7 ;
vl      adj[N] ;
vpll    adjc[N] ;
ll      vis[N] ;
ll      arr[N] ;

ll muld(ll a,ll b)
{
       return (((a%mod)*(b%mod))%mod);
}
ll sumd(ll a,ll b)
{
       return (((a%mod)+(b%mod))%mod);
}
ll subd(ll a,ll b)
{
       return (((a%mod)-(b%mod)+mod)%mod);
}

int main()
{
    IOS;
    ll a, b, c, d, n, m, p, x, y, z, i, j, k, f = 0, tc, cnt = 0, sum = 0, mul = 1, mi = 1e18, ma = -1e18, cs;
    string   str ;
    char     ch ;
    double   db ;
    ll       l, r ;
    //code

    cin>>tc;
    for(cs=1;cs<=tc;cs++)
    {
        cin>>n>>m;
        ll M[n][m];
        for(i=0;i<n;i++)
        {
               for(j=0;j<m;j++)
               {
                      cin>>M[i][j];
               }
        }

        for(i=0;i<n;i++)
        {
               for(j=0;j<m;j++)
               {
                     x=M[i][j];
                     if(i-1>=0&&x==M[i-1][j])
                     {
                            f=0;
                           if(i-1>=0&&x+1==M[i-1][j]) f=1;
                           else if(j-1>=0&&x+1==M[i-1][j]) f=1;
                           else if(i+1<n&&x+1==M[i+1][j]) f=1;
                           else if(j+1<m&&x+1==M[i][j+1]) f=1;
                           if(f==0){
                               M[i][j]=x+1;
                           }
                     }
                     else if(j-1>=0&&x==M[i][j-1])
                     {
                           f=0;
                           if(i-1>=0&&x+1==M[i-1][j]) f=1;
                           else if(j-1>=0&&x+1==M[i-1][j]) f=1;
                           else if(i+1<n&&x+1==M[i+1][j]) f=1;
                           else if(j+1<m&&x+1==M[i][j+1]) f=1;
                           if(f==0){
                               M[i][j]=x+1;
                           }
                     }
                     else if(i+1<n&&x==M[i+1][j])
                     {
                             f=0;
                           if(i-1>=0&&x+1==M[i-1][j]) f=1;
                           else if(j-1>=0&&x+1==M[i-1][j]) f=1;
                           else if(i+1<n&&x+1==M[i+1][j]) f=1;
                           else if(j+1<m&&x+1==M[i][j+1]) f=1;
                           if(f==0){
                               M[i][j]=x+1;
                           }
                     }
                     else if(j+1<m&&x==M[i][j+1])
                     {
                             f=0;
                           if(i-1>=0&&x+1==M[i-1][j]) f=1;
                           else if(j-1>=0&&x+1==M[i-1][j]) f=1;
                           else if(i+1<n&&x+1==M[i+1][j]) f=1;
                           else if(j+1<m&&x+1==M[i][j+1]) f=1;
                           if(f==0){
                               M[i][j]=x+1;
                           }
                     }

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

    }

    //code
    return 0;
}


#include<bits/stdc++.h>
#define        u64             uint64_t
#define        ll              long long
#define        endl            "\n"
#define        PI              acos(-1)
#define        fi              first
#define        si              second
#define        mkp             make_pair
#define        pb              push_back
#define        set0(arr)       memset(arr, 0, sizeof(arr))
#define        setinf(arr)     memset(arr, 126, sizeof(arr))
#define        all(x)          (x).begin(),(x).end()
#define        sz(v)           ((ll)(v).size())
#define        IOS             ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
using namespace std;
using          pll        =      pair<ll, ll> ;
using          vl         =      vector<ll> ;
using          vpll       =      vector<pll> ;
using          mll        =      map<ll, ll> ;
using          mcl        =      map<char, ll> ;
using          msl        =      map<string,ll> ;
using          sl         =      set<ll> ;
using          sc         =      set<char> ;
using          dl         =      deque<ll> ;
const int N = 1e6+5 ;

ll      mod = 1e9+7 ;
vl      adj[N] ;
vpll    adjc[N] ;
ll      vis[N] ;
ll      arr[N] ;

ll muld(ll a,ll b)
{
       return (((a%mod)*(b%mod))%mod);
}
ll sumd(ll a,ll b)
{
       return (((a%mod)+(b%mod))%mod);
}
ll subd(ll a,ll b)
{
       return (((a%mod)-(b%mod)+mod)%mod);
}

int main()
{
    IOS;
    ll a, b, c, d, n, m, p, x, y, z, i, j, k, f = 0, tc, cnt = 0, sum = 0, mul = 1, mi = 1e18, ma = -1e18, cs;
    string   str ;
    char     ch ;
    double   db ;
    ll       l, r ;
    //code

    cin>>tc;
    for(cs=1;cs<=tc;cs++)
    {
        cin>>n>>m;
        ll M[n][m];
        for(i=0;i<n;i++)
        {
               for(j=0;j<m;j++)
               {
                      cin>>M[i][j];
               }
        }
        ll M1[n][m];
        for(i=0;i<n;i++)
        {
               for(j=0;j<m;j++)
               {
                     x=M[i][j];
                     if(i-1>=0&&x==M[i-1][j])
                     {
                           x++;
                     }
                     else if(j-1>=0&&x==M[i][j-1])
                     {
                            x++;
                     }
                     else if(i+1<n&&x==M[i+1][j])
                            x++;
                     else if(j+1<m&&x==M[i][j+1])
                            x++;
                     M[i][j]=x;
               }
        }
        for(i=0;i<n;i++)
        {
               for(j=0;j<m;j++)
                     cout<<M[i][j]<<" ";
               cout<<endl;
        }

    }

    //code
    return 0;
}


#include<bits/stdc++.h>
#define        u64             uint64_t
#define        ll              long long
#define        endl            "\n"
#define        PI              acos(-1)
#define        fi              first
#define        si              second
#define        mkp             make_pair
#define        pb              push_back
#define        set0(arr)       memset(arr, 0, sizeof(arr))
#define        setinf(arr)     memset(arr, 126, sizeof(arr))
#define        all(x)          (x).begin(),(x).end()
#define        sz(v)           ((ll)(v).size())
#define        IOS             ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
using namespace std;
using          pll        =      pair<ll, ll> ;
using          vl         =      vector<ll> ;
using          vpll       =      vector<pll> ;
using          mll        =      map<ll, ll> ;
using          mcl        =      map<char, ll> ;
using          msl        =      map<string,ll> ;
using          sl         =      set<ll> ;
using          sc         =      set<char> ;
using          dl         =      deque<ll> ;
const int N = 1e6+5 ;

ll      mod = 1e9+7 ;
vl      adj[N] ;
vpll    adjc[N] ;
ll      vis[N] ;
ll      arr[N] ;

ll muld(ll a,ll b)
{
       return (((a%mod)*(b%mod))%mod);
}
ll sumd(ll a,ll b)
{
       return (((a%mod)+(b%mod))%mod);
}
ll subd(ll a,ll b)
{
       return (((a%mod)-(b%mod)+mod)%mod);
}

int main()
{
    IOS;
    ll a, b, c, d, n, m, p, x, y, z, i, j, k, f = 0, tc, cnt = 0, sum = 0, mul = 1, mi = 1e18, ma = -1e18, cs;
    string   str ;
    char     ch ;
    double   db ;
    ll       l, r ;
    //code

    cin>>tc;
    for(cs=1;cs<=tc;cs++)
    {
        cin>>n>>m;
        ll M[n][m];
        for(i=0;i<n;i++)
        {
               for(j=0;j<m;j++)
               {
                      cin>>M[i][j];
               }
        }
        ll M1[n][m];
        for(i=0;i<n;i++)
        {
               for(j=0;j<m;j++)
               {
                     x=M[i][j];
                     if(i-1>=0&&x==M[i-1][j])
                     {
                           M[i][j]=x+1;
                           if(j-1>=0&&x+1==M[i][j-1])
                           {
                                  M[i][j-1]++;
                           }
                     }
                     else if(j-1>=0&&x==M[i][j-1])
                     {
                           M[i][j]=x+1;
                           if(i-1>=0&&x+1==M[i-1][j])
                           {
                                  M[i-1][j]++;
                           }
                     }

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

    }

    //code
    return 0;
}


#include<bits/stdc++.h>
#define        u64             uint64_t
#define        ll              long long
#define        endl            "\n"
#define        PI              acos(-1)
#define        fi              first
#define        si              second
#define        mkp             make_pair
#define        pb              push_back
#define        set0(arr)       memset(arr, 0, sizeof(arr))
#define        setinf(arr)     memset(arr, 126, sizeof(arr))
#define        all(x)          (x).begin(),(x).end()
#define        sz(v)           ((ll)(v).size())
#define        IOS             ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
using namespace std;
using          pll        =      pair<ll, ll> ;
using          vl         =      vector<ll> ;
using          vpll       =      vector<pll> ;
using          mll        =      map<ll, ll> ;
using          mcl        =      map<char, ll> ;
using          msl        =      map<string,ll> ;
using          sl         =      set<ll> ;
using          sc         =      set<char> ;
using          dl         =      deque<ll> ;
const int N = 1e6+5 ;

ll      mod = 1e9+7 ;
vl      adj[N] ;
vpll    adjc[N] ;
ll      vis[N] ;
ll      arr[N] ;

ll muld(ll a,ll b)
{
       return (((a%mod)*(b%mod))%mod);
}
ll sumd(ll a,ll b)
{
       return (((a%mod)+(b%mod))%mod);
}
ll subd(ll a,ll b)
{
       return (((a%mod)-(b%mod)+mod)%mod);
}

int main()
{
    IOS;
    ll a, b, c, d, n, m, p, x, y, z, i, j, k, f = 0, tc, cnt = 0, sum = 0, mul = 1, mi = 1e18, ma = -1e18, cs;
    string   str ;
    char     ch ;
    double   db ;
    ll       l, r ;
    //code

    cin>>tc;
    for(cs=1;cs<=tc;cs++)
    {
        cin>>n>>m;
        ll M[n][m];
        for(i=0;i<n;i++)
        {
               for(j=0;j<m;j++)
               {
                      cin>>M[i][j];
               }
        }

        for(i=0;i<n;i++)
        {
               for(j=0;j<m;j++)
               {
                     if((i+j)%2==0)
                     {
                            if(M[i][j]%2==1) M[i][j]++;

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

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

    }

    //code
    return 0;
}


#include<bits/stdc++.h>
#define        u64             uint64_t
#define        ll              long long
#define        endl            "\n"
#define        PI              acos(-1)
#define        fi              first
#define        si              second
#define        mkp             make_pair
#define        pb              push_back
#define        set0(arr)       memset(arr, 0, sizeof(arr))
#define        setinf(arr)     memset(arr, 126, sizeof(arr))
#define        all(x)          (x).begin(),(x).end()
#define        sz(v)           ((ll)(v).size())
#define        IOS             ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
using namespace std;
using          pll        =      pair<ll, ll> ;
using          vl         =      vector<ll> ;
using          vpll       =      vector<pll> ;
using          mll        =      map<ll, ll> ;
using          mcl        =      map<char, ll> ;
using          msl        =      map<string,ll> ;
using          sl         =      set<ll> ;
using          sc         =      set<char> ;
using          dl         =      deque<ll> ;
const int N = 1e6+5 ;

ll      mod = 1e9+7 ;
vl      adj[N] ;
vpll    adjc[N] ;
ll      vis[N] ;
ll      arr[N] ;

ll muld(ll a,ll b)
{
       return (((a%mod)*(b%mod))%mod);
}
ll sumd(ll a,ll b)
{
       return (((a%mod)+(b%mod))%mod);
}
ll subd(ll a,ll b)
{
       return (((a%mod)-(b%mod)+mod)%mod);
}

int main()
{
    IOS;
    ll a, b, c, d, n, m, p, x, y, z, i, j, k, f = 0, tc, cnt = 0, sum = 0, mul = 1, mi = 1e18, ma = -1e18, cs;
    string   str ;
    char     ch ;
    double   db ;
    ll       l, r ;
    //code

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

    //code
    return 0;
}


#include<bits/stdc++.h>
#define        u64             uint64_t
#define        ll              long long
#define        endl            "\n"
#define        PI              acos(-1)
#define        fi              first
#define        si              second
#define        mkp             make_pair
#define        pb              push_back
#define        set0(arr)       memset(arr, 0, sizeof(arr))
#define        setinf(arr)     memset(arr, 126, sizeof(arr))
#define        all(x)          (x).begin(),(x).end()
#define        sz(v)           ((ll)(v).size())
#define        IOS             ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
using namespace std;
using          pll        =      pair<ll, ll> ;
using          vl         =      vector<ll> ;
using          vpll       =      vector<pll> ;
using          mll        =      map<ll, ll> ;
using          mcl        =      map<char, ll> ;
using          msl        =      map<string,ll> ;
using          sl         =      set<ll> ;
using          sc         =      set<char> ;
using          dl         =      deque<ll> ;
const int N = 1e6+5 ;

ll      mod = 1e9+7 ;
vl      adj[N] ;
vpll    adjc[N] ;
ll      vis[N] ;
ll      arr[N] ;

ll muld(ll a,ll b)
{
       return (((a%mod)*(b%mod))%mod);
}
ll sumd(ll a,ll b)
{
       return (((a%mod)+(b%mod))%mod);
}
ll subd(ll a,ll b)
{
       return (((a%mod)-(b%mod)+mod)%mod);
}

int main()
{
    IOS;
    ll a, b, c, d, n, m, p, x, y, z, i, j, k, f = 0, tc, cnt = 0, sum = 0, mul = 1, mi = 1e18, ma = -1e18, cs;
    string   str ;
    char     ch ;
    double   db ;
    ll       l, r ;
    //code

    cin>>tc;
    for(cs=1;cs<=tc;cs++)
    {
        cin>>n>>m;
        ll M[n][m];
        for(i=0;i<n;i++)
        {
               for(j=0;j<m;j++)
               {
                      cin>>M[i][j];
               }
        }

        for(i=0;i<n;i++)
        {
               for(j=0;j<m;j++)
               {
                     x=M[i][j];
                     if(i-1>=0&&x==M[i-1][j])
                     {
                           f=0;
                           if(i-1>=0&&x+1==M[i-1][j]) f=1;
                           else if(j-1>=0&&x+1==M[i][j-1]) f=1;
                           if(f==0){
                               M[i][j]=x+1;
                           }
                     }
                     else if(j-1>=0&&x==M[i][j-1])
                     {
                           f=0;
                           if(i-1>=0&&x+1==M[i-1][j]) f=1;
                           else if(j-1>=0&&x+1==M[i][j-1]) f=1;
                           if(f==0){
                               M[i][j]=x+1;
                           }
                     }
                     else if(i+1<n&&x==M[i+1][j])
                     {
                           f=0;
                           if(i-1>=0&&x+1==M[i-1][j]) f=1;
                           else if(j-1>=0&&x+1==M[i][j-1]) f=1;
                           if(f==0){
                               M[i][j]=x+1;
                           }
                     }
                     else if(j+1<m&&x==M[i][j+1])
                     {
                           f=0;
                           if(i-1>=0&&x+1==M[i-1][j]) f=1;
                           else if(j-1>=0&&x+1==M[i][j-1]) f=1;
                           if(f==0){
                               M[i][j]=x+1;
                           }
                     }

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

    }

    //code
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

# define deb_v(x) cerr << #x << " = ("; \
    for (auto item: x) cerr << a[i] << " "; \
    cerr << ")\n";

# define deb(x) cerr << #x << " = " << x << "\n";

vector<pair<int, int>> dirs = {{0, 1}, {1, 0}, {0, -1}, {-1, 0}};
set<pair<int, int>> seen;
int n, m;

bool is_valid(int r, int c) {
    return 0 <= r && r < n && 0 <= c && c < m;
}

/* void search(int r, int c, vector<vector<int>>& a) { */
/*     for (pair<int, int>& dir : dirs) { */
/*         int new_r = r + dir.first, new_c = c + dir.second; */
/*         if (is_valid(new_r, new_c) && a[new_r][new_c] == a[r][c]) { */
/*             if (seen.count({new_r, new_c}) == 0) { */
/*                 a[new_r][new_c]++; */
/*                 seen.insert({new_r, new_c}); */
/*                 search(new_r, new_c, a); */
/*             } else { */
/*                 assert(seen.count({r, c}) == 0); */
/*                 a[r][c]++; */
/*                 seen.insert({r, c}); */
/*                 search(r, c, a); */
/*             } */
/*         } */
/*     } */
/* } */

int get_damage(vector<vector<int>>& a, int r, int c) {
    int damage = 0;
    for (pair<int, int>& dir : dirs) {
        int n_r = r + dir.first, n_c = c + dir.second;
        if (is_valid(n_r, n_c) && a[r][c] + 1 == a[n_r][n_c]) {
            damage++;
        }
    }
    return damage;
}

void solve(int t) {
    seen.clear();
    scanf("%d%d", &n, &m);
    vector<vector<int>> a(n, vector<int>(m));
    for (int r = 0; r < n; r++) {
        for (int c = 0; c < m; c++) {
            scanf("%d", &a[r][c]);
        }
    }
    for (int r = 0; r < n; r++) {
        for (int c = 0; c < m; c++) {
            vector<vector<int>> damage;
            for (pair<int, int>& dir : dirs) {
                int n_r = r + dir.first, n_c = c + dir.second;
                if (is_valid(n_r, n_c) && a[r][c] == a[n_r][n_c]) {
                    damage.push_back({get_damage(a, r, c), r, c});
                    damage.push_back({get_damage(a, n_r, n_c), n_r, n_c});
                }
            }
            int d_n = damage.size();
            if (d_n == 0) {
                continue;
            }
            sort(damage.begin(), damage.end());
            int i = 0;
            int inc_r = damage[0][1], inc_c = damage[0][2];
            while (i < d_n && seen.count({inc_r, inc_c}) != 0) {
                inc_r = damage[i][1];
                inc_c = damage[i][2];
                i++;
            }
            assert(i < d_n);
            a[inc_r][inc_c]++;
            seen.insert({inc_r, inc_c});
            /* search(r, c, a); */
        }
    }
    for (int r = 0; r < n; r++) {
        for (int c = 0; c < m; c++) {
            for (pair<int, int>& d : dirs) {
                int n_r = r + d.first, n_c = c + d.second;
                if (is_valid(n_r, n_c)) {
                    assert (a[r][c] != a[n_r][n_c]);
                }
            }
            printf("%d ", a[r][c]);
        }
        printf("\n");
    }
}

int main() {
    int t;
    scanf("%d", &t);
    for (int i = 1; i <= t; i++) {
        solve(i);
    }
}


#include <bits/stdc++.h>

using namespace std;

# define deb_v(x) cerr << #x << " = ("; \
    for (auto item: x) cerr << a[i] << " "; \
    cerr << ")\n";

# define deb(x) cerr << #x << " = " << x << "\n";

vector<pair<int, int>> dirs = {{0, 1}, {1, 0}, {0, -1}, {-1, 0}};
set<pair<int, int>> seen;
int n, m;

bool is_valid(int r, int c) {
    return 0 <= r && r < n && 0 <= c && c < m;
}

void search(int r, int c, vector<vector<int>>& a) {
    for (pair<int, int>& dir : dirs) {
        int new_r = r + dir.first, new_c = c + dir.second;
        if (is_valid(new_r, new_c) && a[new_r][new_c] == a[r][c]) {
            if (seen.count({new_r, new_c}) == 0) {
                a[new_r][new_c]++;
                seen.insert({new_r, new_c});
                search(new_r, new_c, a);
            } else {
                assert(seen.count({r, c}) == 0);
                a[r][c]++;
                seen.insert({r, c});
                search(r, c, a);
            }
        }
    }
}

void solve(int t) {
    scanf("%d%d", &n, &m);
    vector<vector<int>> a(n, vector<int>(m));
    for (int r = 0; r < n; r++) {
        for (int c = 0; c < m; c++) {
            scanf("%d", &a[r][c]);
        }
    }
    for (int r = 0; r < n; r++) {
        for (int c = 0; c < m; c++) {
            search(r, c, a);
            /* for (pair<int, int>& dir : dirs) { */
            /*     int new_r = r + dir.first, new_c = c + dir.second; */
            /*     if (is_valid(new_r, new_c, n, m) && a[new_r][new_c] == a[r][c]) { */
            /*         if (seen.count({new_r, new_d}) == 0) { */
            /*             search(new_r, new_d); */
            /*         } else { */
            /*             assert(seen.count({r, c}) == 0); */
            /*             search(r, c); */
            /*         } */
            /*     } */
            /* } */
        }
    }
    /* vector<vector<bool>> marked(n, vector<bool>(m, false)); */
    /* for (int r = 0; r < n; r++) { */
    /*     for (int c = 0; c < m; c++) { */
    /*         for (pair<int, int>& d : dirs) { */
    /*             int n_r = d.first + r, n_c = d.second + c; */
    /*             if (is_valid(n_r, n_c, n, m) && a[r][c] == a[n_r][n_c]) { */
    /*                 if (!marked[n_r][n_c]) { */
    /*                     marked[n_r][n_c] = true; */
    /*                     a[n_r][n_c]++; */
    /*                 } else { */
    /*                     assert (marked[r][c] == false); */
    /*                     marked[r][c] = true; */
    /*                     a[r][c]++; */
    /*                 } */
    /*             } */
    /*         } */
    /*     } */
    /* } */
    for (int r = 0; r < n; r++) {
        for (int c = 0; c < m; c++) {
            for (pair<int, int>& d : dirs) {
                int n_r = r + d.first, n_c = c + d.second;
                if (is_valid(n_r, n_c)) {
                    assert (a[r][c] != a[n_r][n_c]);
                }
            }
            printf("%d ", a[r][c]);
        }
        printf("\n");
    }
}

int main() {
    int t;
    scanf("%d", &t);
    for (int i = 1; i <= t; i++) {
        solve(i);
    }
}


#include <bits/stdc++.h>

using namespace std;

# define deb_v(x) cerr << #x << " = ("; \
    for (auto item: x) cerr << a[i] << " "; \
    cerr << ")\n";

# define deb(x) cerr << #x << " = " << x << "\n";

vector<pair<int, int>> dirs = {{0, 1}, {1, 0}, {0, -1}, {-1, 0}};
set<pair<int, int>> seen;
int n, m;

bool is_valid(int r, int c) {
    return 0 <= r && r < n && 0 <= c && c < m;
}

void search(int r, int c, vector<vector<int>>& a) {
    for (pair<int, int>& dir : dirs) {
        int new_r = r + dir.first, new_c = c + dir.second;
        if (is_valid(new_r, new_c) && a[new_r][new_c] == a[r][c]) {
            if (seen.count({new_r, new_c}) == 0) {
                a[new_r][new_c]++;
                search(new_r, new_c, a);
            } else {
                assert(seen.count({r, c}) == 0);
                a[r][c]++;
                search(r, c, a);
            }
        }
    }
}

void solve(int t) {
    scanf("%d%d", &n, &m);
    vector<vector<int>> a(n, vector<int>(m));
    for (int r = 0; r < n; r++) {
        for (int c = 0; c < m; c++) {
            scanf("%d", &a[r][c]);
        }
    }
    for (int r = 0; r < n; r++) {
        for (int c = 0; c < m; c++) {
            search(r, c, a);
            /* for (pair<int, int>& dir : dirs) { */
            /*     int new_r = r + dir.first, new_c = c + dir.second; */
            /*     if (is_valid(new_r, new_c, n, m) && a[new_r][new_c] == a[r][c]) { */
            /*         if (seen.count({new_r, new_d}) == 0) { */
            /*             search(new_r, new_d); */
            /*         } else { */
            /*             assert(seen.count({r, c}) == 0); */
            /*             search(r, c); */
            /*         } */
            /*     } */
            /* } */
        }
    }
    /* vector<vector<bool>> marked(n, vector<bool>(m, false)); */
    /* for (int r = 0; r < n; r++) { */
    /*     for (int c = 0; c < m; c++) { */
    /*         for (pair<int, int>& d : dirs) { */
    /*             int n_r = d.first + r, n_c = d.second + c; */
    /*             if (is_valid(n_r, n_c, n, m) && a[r][c] == a[n_r][n_c]) { */
    /*                 if (!marked[n_r][n_c]) { */
    /*                     marked[n_r][n_c] = true; */
    /*                     a[n_r][n_c]++; */
    /*                 } else { */
    /*                     assert (marked[r][c] == false); */
    /*                     marked[r][c] = true; */
    /*                     a[r][c]++; */
    /*                 } */
    /*             } */
    /*         } */
    /*     } */
    /* } */
    for (int r = 0; r < n; r++) {
        for (int c = 0; c < m; c++) {
            for (pair<int, int>& d : dirs) {
                int n_r = r + d.first, n_c = c + d.second;
                if (is_valid(n_r, n_c)) {
                    assert (a[r][c] != a[n_r][n_c]);
                }
            }
            printf("%d ", a[r][c]);
        }
        printf("\n");
    }
}

int main() {
    int t;
    scanf("%d", &t);
    for (int i = 1; i <= t; i++) {
        solve(i);
    }
}


#include <bits/stdc++.h>

using namespace std;

# define deb_v(x) cerr << #x << " = ("; \
    for (auto item: x) cerr << a[i] << " "; \
    cerr << ")\n";

# define deb(x) cerr << #x << " = " << x << "\n";

void solve(int t) {
    int n, m;
    scanf("%d%d", &n, &m);
    for (int r = 0; r < n; r++) {
        for (int c = 0; c < m; c++) {
            int x;
            scanf("%d", &x);
            if ((r + c) % 2 == 0) {
                if (x % 2 == 1) {
                    x++;
                }
            } else {
                if (x % 2 == 0) {
                    x++;
                }
            }
            printf("%d ", x);
        }
        printf("\n");
    }
}

int main() {
    int t;
    scanf("%d", &t);
    for (int i = 1; i <= t; i++) {
        solve(i);
    }
}


#include <bits/stdc++.h>

using namespace std;

# define deb_v(x) cerr << #x << " = ("; \
    for (auto item: x) cerr << a[i] << " "; \
    cerr << ")\n";

# define deb(x) cerr << #x << " = " << x << "\n";

vector<pair<int, int>> dirs = {{0, 1}, {1, 0}, {0, -1}, {-1, 0}};
set<pair<int, int>> seen;
int n, m;

bool is_valid(int r, int c) {
    return 0 <= r && r < n && 0 <= c && c < m;
}

void search(int r, int c, vector<vector<int>>& a) {
    for (pair<int, int>& dir : dirs) {
        int new_r = r + dir.first, new_c = c + dir.second;
        if (is_valid(new_r, new_c) && a[new_r][new_c] == a[r][c]) {
            if (seen.count({new_r, new_c}) == 0) {
                a[new_r][new_c]++;
                seen.insert({new_r, new_c});
                search(new_r, new_c, a);
            } else {
                assert(seen.count({r, c}) == 0);
                a[r][c]++;
                seen.insert({r, c});
                search(r, c, a);
            }
        }
    }
}

void solve(int t) {
    scanf("%d%d", &n, &m);
    vector<vector<int>> a(n, vector<int>(m));
    for (int r = 0; r < n; r++) {
        for (int c = 0; c < m; c++) {
            scanf("%d", &a[r][c]);
        }
    }
    for (int r = 0; r < n; r++) {
        for (int c = 0; c < m; c++) {
            search(r, c, a);
        }
    }
    for (int r = 0; r < n; r++) {
        for (int c = 0; c < m; c++) {
            for (pair<int, int>& d : dirs) {
                int n_r = r + d.first, n_c = c + d.second;
                /* if (is_valid(n_r, n_c)) { */
                /*     assert (a[r][c] != a[n_r][n_c]); */
                /* } */
            }
            printf("%d ", a[r][c]);
        }
        printf("\n");
    }
}

int main() {
    int t;
    scanf("%d", &t);
    for (int i = 1; i <= t; i++) {
        solve(i);
    }
}


#include <bits/stdc++.h>

using namespace std;

# define deb_v(x) cerr << #x << " = ("; \
    for (auto item: x) cerr << a[i] << " "; \
    cerr << ")\n";

# define deb(x) cerr << #x << " = " << x << "\n";

vector<pair<int, int>> dirs = {{0, 1}, {1, 0}, {0, -1}, {-1, 0}};
set<pair<int, int>> seen;
int n, m;

bool is_valid(int r, int c) {
    return 0 <= r && r < n && 0 <= c && c < m;
}

void search(int r, int c, vector<vector<int>>& a) {
    for (pair<int, int>& dir : dirs) {
        int new_r = r + dir.first, new_c = c + dir.second;
        if (is_valid(new_r, new_c) && a[new_r][new_c] == a[r][c]) {
            if (seen.count({new_r, new_c}) == 0) {
                a[new_r][new_c]++;
                search(new_r, new_c, a);
            } else {
                assert(seen.count({r, c}) == 0);
                search(r, c, a);
            }
        }
    }
}

void solve(int t) {
    scanf("%d%d", &n, &m);
    vector<vector<int>> a(n, vector<int>(m));
    for (int r = 0; r < n; r++) {
        for (int c = 0; c < m; c++) {
            scanf("%d", &a[r][c]);
        }
    }
    for (int r = 0; r < n; r++) {
        for (int c = 0; c < m; c++) {
            search(r, c, a);
            /* for (pair<int, int>& dir : dirs) { */
            /*     int new_r = r + dir.first, new_c = c + dir.second; */
            /*     if (is_valid(new_r, new_c, n, m) && a[new_r][new_c] == a[r][c]) { */
            /*         if (seen.count({new_r, new_d}) == 0) { */
            /*             search(new_r, new_d); */
            /*         } else { */
            /*             assert(seen.count({r, c}) == 0); */
            /*             search(r, c); */
            /*         } */
            /*     } */
            /* } */
        }
    }
    /* vector<vector<bool>> marked(n, vector<bool>(m, false)); */
    /* for (int r = 0; r < n; r++) { */
    /*     for (int c = 0; c < m; c++) { */
    /*         for (pair<int, int>& d : dirs) { */
    /*             int n_r = d.first + r, n_c = d.second + c; */
    /*             if (is_valid(n_r, n_c, n, m) && a[r][c] == a[n_r][n_c]) { */
    /*                 if (!marked[n_r][n_c]) { */
    /*                     marked[n_r][n_c] = true; */
    /*                     a[n_r][n_c]++; */
    /*                 } else { */
    /*                     assert (marked[r][c] == false); */
    /*                     marked[r][c] = true; */
    /*                     a[r][c]++; */
    /*                 } */
    /*             } */
    /*         } */
    /*     } */
    /* } */
    for (int r = 0; r < n; r++) {
        for (int c = 0; c < m; c++) {
            for (pair<int, int>& d : dirs) {
                int n_r = r + d.first, n_c = c + d.second;
                if (is_valid(n_r, n_c)) {
                    assert (a[r][c] != a[n_r][n_c]);
                }
            }
            printf("%d ", a[r][c]);
        }
        printf("\n");
    }
}

int main() {
    int t;
    scanf("%d", &t);
    for (int i = 1; i <= t; i++) {
        solve(i);
    }
}


#include <bits/stdc++.h>

using namespace std;

# define deb_v(x) cerr << #x << " = ("; \
    for (auto item: x) cerr << a[i] << " "; \
    cerr << ")\n";

# define deb(x) cerr << #x << " = " << x << "\n";

bool is_valid(int r, int c, int n, int m) {
    return 0 <= r && r < n && 0 <= c && c < m;
}

void solve(int t) {
    int n, m;
    scanf("%d%d", &n, &m);
    vector<vector<int>> a(n, vector<int>(m));
    for (int r = 0; r < n; r++) {
        for (int c = 0; c < m; c++) {
            scanf("%d", &a[r][c]);
        }
    }
    vector<vector<bool>> marked(n, vector<bool>(m, false));
    vector<pair<int, int>> dirs = {{0, 1}, {1, 0}, {0, -1}, {-1, 0}};
    for (int r = 0; r < n; r++) {
        for (int c = 0; c < m; c++) {
            for (pair<int, int>& d : dirs) {
                int n_r = d.first + r, n_c = d.second + c;
                if (is_valid(n_r, n_c, n, m) && a[r][c] == a[n_r][n_c]) {
                    if (!marked[n_r][n_c]) {
                        marked[n_r][n_c] = true;
                        a[n_r][n_c]++;
                    } else {
                        assert (marked[r][c] == false);
                        marked[r][c] = true;
                        a[r][c]++;
                    }
                }
            }
        }
    }
    for (int r = 0; r < n; r++) {
        for (int c = 0; c < m; c++) {
            for (pair<int, int>& d : dirs) {
                int n_r = r + d.first, n_c = c + d.second;
                if (is_valid(n_r, n_c, n, m)) {
                    assert (a[r][c] != a[n_r][n_c]);
                }
            }
            printf("%d ", a[r][c]);
        }
        printf("\n");
    }
}

int main() {
    int t;
    scanf("%d", &t);
    for (int i = 1; i <= t; i++) {
        solve(i);
    }
}


#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;
using vii = vector<pii>;
#define fi first
#define se second
#define sz(c)  ((int)(c).size())
#define all(c) (c).begin(), (c).end()
#define forn(i,m, n)  for (int i = m, nnnn = (n); i < nnnn; ++i)
#define pb  push_back
#define mp  make_pair
int P = 998244353;

bool visited[100][100];
ll table[100][100];
ll n, m;

bool dfs1(int j, int l){
    if (visited[j][l]) return false;
    ll curr = table[j][l];
    if (j > 0) if (table[j-1][l] == curr+1){
        if (dfs1(j-1, l) == false){
            return false;
        }
    }
    if (j < n-1) if (table[j+1][l] == curr+1){
        if (dfs1(j+1, l) == false){
            return false;
        }
    }
    if (l > 0) if (table[j][l-1] == curr+1){
        if (dfs1(j, l-1) == false){
            return false;
        }
    }
    if (l < m-1) if (table[j][l-1] == curr+1){
        if (dfs1(j, l-1) == false){
            return false;
        }
    }
    return true;
}

void dfs2(int j, int l){
    visited[j][l] = true;
    ll curr = table[j][l];
    if (j > 0) if (table[j-1][l] == curr && visited[j-1][l] == false){
        table[j-1][l]++;
        dfs2(j-1, l);
    }
    if (j < n-1) if (table[j+1][l] == curr && visited[j+1][l] == false){
        table[j+1][l]++;
        dfs2(j+1, l);
    }
    if (l > 0) if (table[j][l-1] == curr && visited[j][l-1] == false){
        table[j][l-1]++;
        dfs2(j, l-1);
    }
    if (l < m-1) if (table[j][l-1] == curr && visited[j][l+1] == false){
        table[j][l+1]++;
        dfs2(j, l+1);
    }
}

int main() {
    ll t;
    scanf("%lld", &t);
    forn(i, 0, t){
        cin >> n >> m;
        forn(j, 0, n){
            forn(l, 0, m) {
                cin >> table[j][l];
                visited[j][l] = false;
            }
        }
        forn(j, 0, n){
            forn(l, 0, m) {
                ll curr = table[j][l];
                if (j > 0) if (table[j-1][l] == curr){
                    if (dfs1(j, l)) {
                        table[j][l]++;
                        dfs2(j, l);
                    } else {
                        table[j-1][l]++;
                        dfs2(j-1, l);
                    }
                }
                if (j < n-1) if (table[j+1][l] == curr){
                    if (dfs1(j, l)) {
                        table[j][l]++;
                        dfs2(j, l);
                    } else {
                        table[j+1][l]++;
                        dfs2(j+1, l);
                    }
                }
                if (l > 0) if (table[j][l-1] == curr){
                    if (dfs1(j, l)) {
                        table[j][l]++;
                        dfs2(j, l);
                    } else {
                        table[j][l-1]++;
                        dfs2(j, l-1);
                    }
                }
                if (l < m-1) if (table[j][l+1] == curr){
                    if (dfs1(j, l)) {
                        table[j][l]++;
                        dfs2(j, l);
                    } else {
                        table[j][l+1]++;
                        dfs2(j, l+1);
                    }
                }
            }
        }
                forn(j, 0, n){
                    forn(l, 0, m) cout << table[j][l] << ' ';
                    cout << '\n';
                }
    }
}


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

int main(){
	int a,b,x,n,maxi=-1,mini=100001;
	vector<int> v;
	cin>>n>>x;
	while(n--){
		cin>>a>>b;
		if(a>b) swap(a,b);
		maxi=max(maxi,a);
		mini=min(mini,b);
		v.push_back(b);
	}
	//cout<<maxi<<" "<<mini<<endl;

	if(maxi>mini){
		cout<<-1;
		return 0;
	}
	if(x<mini && x>maxi)
	{
		cout<<0;
		return 0;
	}
	cout<<min(abs(x-maxi), abs(x-mini));

	/*
	cout<<maxi-x;
	*/

	return 0;
}


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

int main(){
	int n,x,a,b,m=1001;
	cin>>n>>x;
	while(n--){
		cin>>a>>b;
		if(a<m&&a>x){
			m=a;
		}
	}
	if((m-x)>=0){
		cout<<m-x;
	}
	else{
		cout<<-1;
	}

	return 0;
}


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

int main(){
	int a,b,x,n,maxi,k=-1;
	vector<int> v;
	cin>>n>>x;
	while(n--){
		cin>>a>>b;
		if(a>b) swap(a,b);
		maxi=max(k,a);
		v.push_back(b);
	}
	for(int i=0;i<v.size();i++){
		if(maxi>v[i]){
			cout<<-1;
			return 0;
		}
	}
	if(maxi==0){
		cout<<maxi;
		return 0;
	}
	else{
	cout<<maxi-x;
	}
	return 0;
}


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

int main(){
	int a,b,x,n,maxi,k=-1;
	vector<int> v;
	cin>>n>>x;
	while(n--){
		cin>>a>>b;
		if(a>b) swap(a,b);
		maxi=max(k,a);
		v.push_back(b);
	}
	for(int i=0;i<v.size();i++){
		if(maxi>v[i]){
			cout<<-1;
			return 0;
		}
	}
	if((maxi-x)<0){
		cout<<0;
		return 0;
	}
	if(maxi==0){
		cout<<maxi;
		return 0;
	}
	else{
	cout<<maxi-x;
	}
	return 0;
}


#include <bits/stdc++.h>

using namespace std;

int main(){
	int x,n;
	int a,b;
	int p1 = -1, p2 = 1000;
	cin >> n >> x;
	bool sw = true;
	for (int i = 0; i < n; ++i)
	{
		cin >> a >> b;
		if(a > b) swap(a,b);

		if(a > p2) sw = false;
		if(a > p1) p1 = a;
		if(b < p2) p2 = b;
	}
	if(!sw) return cout << -1,0;

	if(p1 < x and x < p2) cout << 0j;
	else if(x < p1) cout << p1 - x;
	else if(x > p2) cout << x - p2;
	return 0;
}


#include <bits/stdc++.h>

using namespace std;

int main(){
	int x,n;
	int a,b;
	int p1 = -1, p2 = 1000;
	cin >> n >> x;
	bool sw = true;
	for (int i = 0; i < n; ++i)
	{
		cin >> a >> b;
		if(a > b) swap(a,b);

		if(a > p2) sw = false;
		if(a > p1) p1 = a;
		if(b < p2) p2 = b;
	}
	if(!sw) return cout << -1,0;

	if(p1 <= x and x <= p2) cout << 0;
	else if(x < p1) cout << p1 - x;
	else if(x > p2) cout << x - p2;
	else cout << -1;
	return 0;
}


#include <bits/stdc++.h>

using namespace std;

int main(){
	int x,n;
	int a,b;
	int p1 = -1, p2 = 1000;
	cin >> n >> x;
	bool sw = true;
	for (int i = 0; i < n; ++i)
	{
		cin >> a >> b;
		if(a > b) swap(a,b);

		if(a > p2 or b < p1) sw = false;
		if(a > p1) p1 = a;
		if(b < p2) p2 = b;
	}
	if(!sw) return cout << -1,0;
	if(p1 <= x and x <= p2) cout << 0;
	else if(x < p1) cout << p1 - x;
	else if(x > p2) cout << x - p2;
	else cout << -1;
	return 0;
}


#include <bits/stdc++.h>

using namespace std;

int main(){
	int x,n;
	int a,b;
	int p1 = -1, p2 = 1000;
	cin >> n >> x;
	bool sw = true;
	for (int i = 0; i < n; ++i)
	{
		cin >> a >> b;
		if(a > b) swap(a,b);

		if(a > p2) sw = false;
		if(a > p1) p1 = a;
		if(b < p2) p2 = b;
	}
	if(!sw) return cout << -1,0;

	if(p1 < x and x < p2) cout << 0;
	else if(x < p1) cout << p1 - x;
	else if(x > p2) cout << x - p2;
	else cout << -1;
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define MAX LONG_MAX
#define e5  100001
#define SET(a) memset(a,-1,sizeof(a))

// XDZ team  -->( D ) :D
vector< pair < int,int > > v1;

int main ()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
//-----------------------
    int n ,x ,a,b,c=0 ;
    cin>>n>>x;
    if (a>b)
        swap(a,b);

    while (n--)
    {
        cin>>a>>b;
        v1.push_back(make_pair(a,b));
        if(x>a && x>b )
            c+=x-b,x-=(x-b);
        else if (x<a && x<b)
            c+=a-x,x+=(a-x);

    }
    bool ignore = 0;

    for(int i=0; i<v1.size(); i++)
    {
        if(x > v1[i].first && x > v1[i].second )
            ignore = 1;
        else if (x<v1[i].first && x<v1[i].second)
            ignore = 1 ;
    }

    if (ignore)
        cout<<-1<<endl;
    else
        cout<<c;

    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define MAX LONG_MAX
#define e5  100001
#define SET(a) memset(a,-1,sizeof(a))

// XDZ team  -->( D ) :D
vector< pair < int,int > > v1;

int main ()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
//-----------------------
    int n ,x ,a,b,c=0 ;
    cin>>n>>x;

    while (n--)
    {
        cin>>a>>b;

        if (a>b)swap(a,b);

        v1.push_back(make_pair(a,b));

        if(x>a && x>b )
            c+=x-b,x-=(x-b);
        else if (x<a && x<b)
            c+=a-x,x+=(a-x);

    }
    bool ignore = 0;

    for(int i=0; i<v1.size(); i++)
    {
        if(x > v1[i].first && x > v1[i].second )
            ignore = 1;
        else if (x<v1[i].first && x<v1[i].second)
            ignore = 1 ;
    }

    if (ignore)
        cout<<-1<<endl;
    else
        cout<<c;

    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define MAX LONG_MAX
#define e5  100001
#define SET(a) memset(a,-1,sizeof(a))

// XDZ team  -->( D ) :D
vector< pair < int,int > > v1;

int main ()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
//-----------------------
    int n ,x ,a,b,c=0 ;
    cin>>n>>x;
    if (a>b)
        swap(a,b);

    while (n--)
    {
        cin>>a>>b;
        v1.push_back(make_pair(a,b));
        if(x>a && x>b )
            c+=x-b;
        else if (x<a && x<b)
            c+=a-x;
    }
    bool ignore = 0;

    for(int i=0; i<v1.size(); i++)
    {
        if(x > v1[i].first && x > v1[i].second )
            ignore = 1;
        else if (x<v1[i].first && x<v1[i].second)
            ignore = 1 ;
    }

    if (ignore)
        cout<<-1<<endl;
    else
        cout<<c;

    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define MAX LONG_MAX
#define e5  100001
#define SET(a) memset(a,-1,sizeof(a))

// XDZ team  -->( D ) :D
vector<int> v1;
int main ()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
//-----------------------
int n ,x ,a,b,c=0 ;
cin>>n>>x;
if (a>b)
    swap(a,b);

while (n--){
    cin>>a>>b;
    if(x>a && x>b )
        c+=x-b;
    else if (x<a && x<b)
        c+=a-x;
}
cout<<c;

    return 0;
}


#include<bits/stdc++.h>
const int maxn = 110;
using namespace std;
int n, x0;

struct node{
    int a, b;

    friend operator < (const node n1, const node n2){
        return n1.a < n2.a;
    }
};
node p[maxn];

int main(){
    cin>>n>>x0;
    for(int i = 0;i<n;i++){
        cin>>p[i].a>>p[i].b;
        if(p[i].a > p[i].b) swap(p[i].a, p[i].b);
    }
    sort(p, p+n);
    int na = p[0].a, nb = p[0].b;
    for(int i = 1;i<n;i++){
        if(nb < p[i].a){
            cout<<"-1"<<endl;
            return 0;
        }
        na = max(na, p[i].a);
        nb = min(nb, p[i].b);
    }
    int ans = min(abs(x0-nb), abs(x0-na));
    cout<<ans<<endl;
    return 0;
}


#include<bits/stdc++.h>
#define ll __int64
using namespace std;
typedef pair<int, int> pii;

struct node {
	int x, y;
	friend bool operator < (const node n1, const node n2) {
		if(n1.x != n2.x) return n1.x < n2.x;
		return n1.y < n2.y;
	}
}p[105];

int main(){
	int n, x0;
	scanf("%d%d", &n, &x0);
	for(int i = 0; i < n; i++) {
		scanf("%d%d", &p[i].x, &p[i].y);
		if(p[i].x > p[i].y) swap(p[i].x, p[i].y);
	}
	sort(p, p + n);
	int l=x0, r=x0;
	for(int i = 0; i < n; i++) {
		if((p[i].x>=l && p[i].x<=r) || (p[i].y>=l&&p[i].y<=r)) continue;
		if(p[i].y < l) l = p[i].y;
		else if(p[i].x > r) r = p[i].x;
	}
	printf("%d\n", r-l);
    return 0;
}


#include<bits/stdc++.h>
const int maxn = 110;
using namespace std;
int n, x0;

struct node{
    int a, b;

    friend operator < (const node n1, const node n2){
        return n1.a < n2.a;
    }
};
node p[maxn];

int main(){
    cin>>n>>x0;
    for(int i = 0;i<n;i++){
        cin>>p[i].a>>p[i].b;
        if(p[i].a > p[i].b) swap(p[i].a, p[i].b);
    }
    sort(p, p+n);
    int na = p[0].a, nb = p[0].b;
    for(int i = 1;i<n;i++){
        if(nb < p[i].a){
            cout<<"-1"<<endl;
            return 0;
        }
        na = max(na, p[i].a);
        nb = min(nb, p[i].b);
    }
    int ans = min(abs(x0-nb), abs(x0-na));
    if(x0 >= na && x0 <= nb)    ans = 0;
    cout<<ans<<endl;
    return 0;
}


#include<bits/stdc++.h>
#define ll __int64
using namespace std;
typedef pair<int, int> pii;

int vis[1010];

int main(){
	int n, x;
	int xi, yi;
	scanf("%d%d", &n, &x);
	int maxn = 0;
	for(int i = 0; i < n; i++) {
		scanf("%d%d", &xi, &yi);
		if(xi > yi) swap(xi, yi);
		for(int j = xi; j <= yi; j++) {
			vis[j]++;
		}
		maxn = max(maxn, yi);
	}
	int k = x, ans = 1e9;
	while(k<maxn && vis[k] != n)
		k++;
	if(k != n) ans = k - x;
	k = x;
	while(k>=0 && vis[k] != n) k--;
	if(k!=-1) ans = min(ans, x-k);
	ans = (ans == 1e9 ? -1:ans);
	printf("%d\n", ans);
    return 0;
}


#include<bits/stdc++.h>
#define ll __int64
using namespace std;
typedef pair<int, int> pii;

int vis[1010];

int main(){
	int n, x;
	int xi, yi;
	scanf("%d%d", &n, &x);
	int maxn = 0;
	for(int i = 0; i < n; i++) {
		scanf("%d%d", &xi, &yi);
		if(xi > yi) swap(xi, yi);
		for(int j = xi; j <= yi; j++) {
			vis[j]++;
		}
		maxn = max(maxn, yi);
	}
	int k = x, ans = 1e9;
	while(k<=maxn && vis[k] != n)
		k++;
	if(k <= maxn) ans = k - x;
	k = x;
	while(k>=0 && vis[k] != n) k--;
	if(k>=0) ans = min(ans, x-k);
	ans = (ans == 1e9 ? -1:ans);
	printf("%d\n", ans);
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,x;
    cin>>n>>x;
    int a[n],b[n];
    for(int i=0;i<n;i++)
    {
        int a1,b1;
        cin>>a1>>b1;
        a[i]=min(a1,b1);
        b[i]=max(a1,b1);
    }
    int l1=a[0],r1=b[0];
    int flag=0;
    for(int i=1;i<n;i++)
    {
        int l2,r2;
        l2=a[i];
        r2=b[i];
        if(r1<l2 || r2<l1)
        {
            flag=1;
            break;
        }
        else
        {
            l1=max(l1,l2);
            r1=min(r1,r2);
        }
    }
    if(flag==0)
    {
        if(x>=l1 && x<=r1)
        {
            cout<<0<<endl;
        }
        else if(x>r1)
        {
            cout<<x-r1<<endl;
        }
        else
        {
            cout<<l1-x<<endl;
        }
    }
    else
    {
        cout<<-1<<endl;
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,x;
    cin>>n>>x;
    int a[n],b[n];
    for(int i=0;i<n;i++)
    {
        int a1,b1;
        cin>>a1>>b1;
        a[i]=min(a1,b1);
        b[i]=max(a1,b1);
    }
    int l1=a[0],r1=b[0];
    int flag=0;
    for(int i=1;i<n;i++)
    {
        int l2,r2;
        l2=a[i];
        r2=b[i];
        if(r1<l2 || r2<l1)
        {
            flag=1;
            break;
        }
        else
        {
            l1=max(l1,l2);
            r1=min(r1,r2);
        }
    }
    if(flag==0)
    {
        if(n>=l1 && n<=r1)
        {
            cout<<0<<endl;
        }
        else if(n>r1)
        {
            cout<<n-r1<<endl;
        }
        else
        {
            cout<<l1-n<<endl;
        }
    }
    else
    {
        cout<<-1<<endl;
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,x;
    cin>>n>>x;
    int a[n],b[n];
    for(int i=0;i<n;i++)
    {
        int a1,b1;
        cin>>a1>>b1;
        a[i]=min(a1,b1);
        b[i]=max(a1,b1);
    }
    int l1=a[0],r1=b[0];
    int flag=0;
    for(int i=1;i<n;i++)
    {
        int l2,r2;
        l2=a[i];
        r2=b[i];
        if(r1<l2 || r2<l1)
        {
            flag=1;
            break;
        }
        else
        {
            l1=max(l1,l2);
            r1=min(r1,r2);
        }
    }
    if(flag==0)
    {
        if(x>=l1 && x<=r1)
        {
            cout<<0<<endl;
        }
        else if(n>r1)
        {
            cout<<n-r1<<endl;
        }
        else
        {
            cout<<l1-n<<endl;
        }
    }
    else
    {
        cout<<-1<<endl;
    }
    return 0;
}


#include<iostream>
#include<stdio.h>

using namespace std;

int main() {
    int n = 0,
        x = 0,
        a = 0,
        b = 0,
        l = 0,
        r = 0;

    cin>>n>>x;

    for(int i = 1; i<=n; ++i) {
        cin>>a>>b;
        int tmp = max(a,b);
        a = min(a,b);
        b = tmp;
        if(b<x) {
            l = max(l, x-b);
        }
        else if(a>x) {
            r = max(r, a-x);
        }
    }

    cout<<l+r+min(l, r)<<endl;
    return 0;
}


#include<iostream>
#include<stdio.h>

using namespace std;

#define INF 0x3f3f3f3f

int main() {
    int n = 0,
        x = 0,
        a = 0,
        b = 0,
        l = -1,
        r = INF;

    cin>>n>>x;

    for(int i = 1; i<=n; ++i) {
        cin>>a>>b;
        l = max(l, min(a, b));
        r = min(r, max(a, b));
    }

    if(r<l) {
        cout<<-1<<endl;
    }
    else if(l<=x && r>=x) {
        cout<<0<<endl;
    }
    else {
        int mv = min(abs(l-x), abs(r-x));
        cout<<mv<<endl;
    }

    return 0;
}


#include<iostream>
#include<stdio.h>

using namespace std;

#define INF 0x3f3f3f3f

int main() {
    int n = 0,
        x = 0,
        a = 0,
        b = 0,
        l = -1,
        r = INF;

    cin>>n>>x;

    for(int i = 1; i<=n; ++i) {
        cin>>a>>b;
        l = max(l, min(a, b));
        r = min(r, max(a, b));
    }

    if(r<l) {
        cout<<-1<<endl;
    }
    else {
        int mv = min(abs(l-x), abs(r-x));
        cout<<mv<<endl;
    }

    return 0;
}


#include<iostream>
#include<stdio.h>

using namespace std;

int main() {
    int n = 0,
        x = 0,
        a = 0,
        b = 0,
        l = -1,
        r = -1;

    cin>>n>>x;

    for(int i = 1; i<=n; ++i) {
        cin>>a>>b;
        int tmp = max(a,b);
        a = min(a,b);
        b = tmp;
        if(b<=x) {
            l = max(l, x-b);
        }
        if(a>=x) {
            r = max(r, a-x);
        }
    }

    if((l>=0 && r>0) || (r>=0 && l>0)) {
        cout<<-1<<endl;
    }
    else if(l>=0) {
        cout<<l<<endl;
    }
    else if(r>=0) {
        cout<<r<<endl;
    }
    else {
        cout<<0<<endl;
    }
    return 0;
}


//https://codeforces.com/problemset/problem/14/B

#include<bits/stdc++.h>

using namespace std;

int main()
{
	int n,x0;
	cin>>n>>x0;
	int r=2000,l=-1;

	int s,e,b1,b2;
	for(int i=0;i<n;i++)
	{
		cin>>b1>>b2;
		s=min(b1,b2);
		e=max(b1,b2);
		if(s>l)
			l=s;
		if(r>e)
			r=e;
	}

	cout<<l<<" "<<r<<endl;
	if(l!=-1 && r!=2000 && l<=r)
	{
		if(x0<l)
			cout<<l-x0<<endl;
		else if(x0>r)
			cout<<x0-r<<endl;
		else
			cout<<0<<endl;
	}
	else
		cout<<"-1"<<endl;

}


//https://codeforces.com/problemset/problem/14/B

#include<bits/stdc++.h>

using namespace std;

int main()
{
	int n,x0;
	cin>>n>>x0;
	int r=2000,l=-1;

	int s,e,b1,b2;
	for(int i=0;i<n;i++)
	{
		cin>>b1>>b2;
		s=min(b1,b2);
		e=max(b1,b2);
		if(s>l)
			l=s;
		if(r<e)
			r=e;
	}

	//cout<<l<<" "<<e<<endl;
	if(l!=-1 || r!=2000 || l<=r)
	{
		if(x0<l)
			cout<<l-x0<<endl;
		else if(x0>r)
			cout<<x0-r<<endl;
		else
			cout<<0<<endl;
	}
	else
		cout<<"-1"<<endl;

}


//https://codeforces.com/problemset/problem/14/B

#include<bits/stdc++.h>

using namespace std;

int main()
{
	int n,x0;
	cin>>n>>x0;
	int r=2000,l=-1;

	int s,e,b1,b2;
	for(int i=0;i<n;i++)
	{
		cin>>b1>>b2;
		s=min(b1,b2);
		e=max(b1,b2);
		if(s>l)
			l=s;
		if(r>e)
			r=e;
	}

	//cout<<l<<" "<<r<<endl;
	if(l!=-1 && r!=2000 && l<=r)
	{
		if(x0<l)
			cout<<l-x0<<endl;
		else if(x0>r)
			cout<<x0-r<<endl;
		else
			cout<<0<<endl;
	}
	else
		cout<<"-1"<<endl;

}


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

int main(int argc, char** argv) {
  ios_base::sync_with_stdio(false);

  int n, s; cin >> n >> s;
  int far_right = -1;
  int far_left = 1234;

  vector<int> as, bs;
  for (int i = 0; i < n; ++i) {
    int a, b; cin >> a >> b;
    if (a > b) swap(a, b);
    if (a > s || s > b) {
      far_right = max(far_right, a);
      far_left = min(far_left, b);
    }
  }

  int r_result = 0;
  if (far_right != -1 && far_right > s) {
    r_result += far_right - s;
  }

  int l_result = 0;
  if (far_left != 1234 && far_left < s) {
    l_result += s - far_left;
  }

  cout << r_result + l_result << endl;
  return 0;
}


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

int main(int argc, char** argv) {
  ios_base::sync_with_stdio(false);

  int n, s; cin >> n >> s;
  int left_most = 1234;
  int right_most = -1;

  vector<int> as, bs;
  for (int i = 0; i < n; ++i) {
    int a, b; cin >> a >> b;
    if (a > b) swap(a, b);
    as.push_back(a);
    bs.push_back(b);

    left_most = min(left_most, a);
    right_most = max(right_most, b);
  }

  int closest = 1234;
  for (int i = left_most; i <= right_most; ++i) {
    int vcount = 0;
    vector<bool> visited(n, false);
    for (int j = 0; j < n; ++j) {
      if (!visited[j] && as[j] <= i && i <= bs[j]) {
        visited[j] = true;
        ++vcount;
      }
    }
    if (vcount == n) {
      closest = min(closest, abs(i - s));
    }
  }
  if (closest == 1234) {
    cout << -1 << endl;
  } else {
    cout << closest << endl;
  }
  return 0;
}


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

int main(int argc, char** argv) {
  ios_base::sync_with_stdio(false);

  int n, s; cin >> n >> s;
  int left_most = 1234;
  int right_most = -1;

  vector<int> as, bs;
  for (int i = 0; i < n; ++i) {
    int a, b; cin >> a >> b;
    if (a > b) swap(a, b);
    as.push_back(a);
    bs.push_back(b);

    left_most = min(left_most, a);
    right_most = max(right_most, b);
  }

  int closest = 1234;
  for (int i = s; i <= right_most; ++i) {
    int vcount = 0;
    vector<bool> visited(n, false);
    for (int j = 0; j < n; ++j) {
      if (!visited[j] && as[j] <= i && i <= bs[j]) {
        visited[j] = true;
        ++vcount;
      }
    }
    if (vcount == n) {
      closest = min(closest, abs(i - s));
      break;
    }
  }

  for (int i = s - 1; i >= left_most; --i) {
    int vcount = 0;
    vector<bool> visited(n, false);
    for (int j = 0; j < n; ++j) {
      if (!visited[j] && as[j] <= i && i <= bs[j]) {
        visited[j] = true;
        ++vcount;
      }
    }
    if (vcount == n) {
      closest = min(closest, abs(i - s));
      break;
    }
  }
  if (closest == 1234) {
    cout << -1 << endl;
  } else {
    cout << closest << endl;
  }
  return 0;
}


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

int main(int argc, char** argv) {
  ios_base::sync_with_stdio(false);

  int n, s; cin >> n >> s;
  int left_most = 1234;
  int right_most = -1;

  vector<int> as, bs;
  for (int i = 0; i < n; ++i) {
    int a, b; cin >> a >> b;
    if (a > b) swap(a, b);
    as.push_back(a);
    bs.push_back(b);

    left_most = min(left_most, a);
    right_most = max(right_most, b);
  }

  int closest = 1234;
  for (int i = left_most; i <= right_most; ++i) {
    int vcount = 0;
    vector<bool> visited(n, false);
    for (int j = 0; j < n; ++j) {
      if (!visited[j] && as[j] <= i && i <= bs[j]) {
        visited[j] = true;
        ++vcount;
      }
    }
    if (vcount == n) {
      closest = min(closest, abs(i - s));
      break;
    }
  }
  if (closest == 1234) {
    cout << -1 << endl;
  } else {
    cout << closest << endl;
  }
  return 0;
}


#include <bits/stdc++.h>
using namespace std;
pair<int,int> intersect(int ai,int bi,int a,int b){
    if(a>b) swap(a,b);
    if(a<=bi) return {a,min(bi,b)};
    return {-1,-1};
}

int main(){
    int n,x;cin>>n>>x;
    int ans=0;
    pair<int,int> p={0,1000};
    for(int i=0;i<n;i++){
        int a,b;cin>>a>>b;
        p=intersect(p.first,p.second,a,b);
        if(p.first==-1 && p.second==-1) ans=-1;
    }
    if(ans==-1) return cout<<-1 ,0;
    if(x>=p.first && x<=p.second) return cout<<0 ,0;
    cout<<min(abs(x-p.first),abs(x-p.second));
    //pair<int,int> p={0,5000};
    //cout<<intersect(2,7,4,6).first<<intersect(2,7,4,6).second;

    return 0;
}


#include <bits/stdc++.h>
using namespace std;
pair<int,int> intersect(int ai,int bi,int a,int b){
    if(a>b) swap(a,b);
    if(a<=bi) return {a,min(bi,b)};
    return {-1,-1};
}

int main(){
    int n,x;cin>>n>>x;
    int ans;
    pair<int,int> p={0,1000};
    for(int i=0;i<n;i++){
        int a,b;cin>>a>>b;
        p=intersect(p.first,p.second,a,b);
        if(p.first==-1 && p.second==-1) ans=-1;
    }
    if(ans==-1) return cout<<-1 ,0;
    if(x>=p.first && x<=p.second) return cout<<0 ,0;
    cout<<min(abs(x-p.first),abs(x-p.second));
    //pair<int,int> p={0,5000};
    //cout<<intersect(2,7,4,6).first<<intersect(2,7,4,6).second;

    return 0;
}


#include <bits/stdc++.h>
using namespace std;
pair<int,int> intersect(int ai,int bi,int a,int b){
    if(a>b) swap(a,b);
    if(a<=bi && b>=bi ) return {max(a,ai),min(bi,b)};
    return {-1,-1};
}

int main(){
    int n,x;cin>>n>>x;
    int ans=0;
    pair<int,int> p={0,1000};
    for(int i=0;i<n;i++){
        int a,b;cin>>a>>b;
        p=intersect(p.first,p.second,a,b);
        if(p.first==-1 && p.second==-1) ans=-1;
    }
    if(ans==-1) return cout<<-1 ,0;
    if(x>=p.first && x<=p.second) return cout<<0 ,0;
    cout<<min(abs(x-p.first),abs(x-p.second));

    return 0;
}


#include <bits/stdc++.h>
using namespace std;
pair<int,int> intersect(int ai,int bi,int a,int b){
    if(a>b) swap(a,b);
    if(a<=bi ) return {max(a,ai),min(bi,b)};
    return {-1,-1};
}

int main(){
    int n,x;cin>>n>>x;
    int ans=0;
    pair<int,int> p={0,1000};
    for(int i=0;i<n;i++){
        int a,b;cin>>a>>b;
        p=intersect(p.first,p.second,a,b);
        if(p.first==-1 && p.second==-1) ans=-1;
    }
    if(ans==-1) return cout<<-1 ,0;
    if(x>=p.first && x<=p.second) return cout<<0 ,0;
    cout<<min(abs(x-p.first),abs(x-p.second));
    //pair<int,int> p={0,5000};

    return 0;
}


#include <bits/stdc++.h>
using namespace std;
pair<int,int> intersect(int ai,int bi,int a,int b){
    if(a>b) swap(a,b);
    if((a<=bi && b>=bi) ||(b>=ai && b<=bi) ) return {max(a,ai),min(bi,b)};
    return {-1,-1};
}

int main(){
    int n,x;cin>>n>>x;
    int ans=0;
    pair<int,int> p={0,1000};
    for(int i=0;i<n;i++){
        int a,b;cin>>a>>b;
        p=intersect(p.first,p.second,a,b);
        if(p.first==-1 && p.second==-1) ans=-1;
    }
    if(ans==-1) return cout<<-1 ,0;
    if(x>=p.first && x<=p.second) return cout<<0 ,0;
    cout<<min(abs(x-p.first),abs(x-p.second));
    //cout<<intersect(2 ,7,4 ,6).first<<" "<<intersect(2 ,7,4 ,6).second;

    return 0;
}


import java.io.*;

public class CF2 {
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        PrintWriter pw = new PrintWriter(new OutputStreamWriter(System.out));

        Task solver = new Task();
        solver.solve(br, pw);

        pw.close();
    }

    static class Task {
        public void solve(BufferedReader br, PrintWriter pw) throws IOException {
            int n = Integer.parseInt(br.readLine());
            if (n % 2 == 1) {
                pw.println(-1);
                return;
            }

            int rowLen = 2;
            StringBuilder layer = new StringBuilder(
                           "bb\n" +
                           "bb\n");

            int numRows = 2;
            boolean black = false;
            int end = (n - 2) / 2;
            for (int i = 0; i < end; i++) {
                char c = black ? 'b' : 'w';

                int start = 0;
                for (int j = 0; j < numRows; j++) {
                    layer.insert(start, c);
                    start += rowLen + 1;
                    layer.insert(start, c);
                    start += 2;
                }

                rowLen += 2;
                numRows += 2;

                StringBuilder row = new StringBuilder();
                for (int j = 0; j < rowLen; j++) {
                    row.append(c);
                }
                row.append("\n");
                layer.insert(0, row);
                layer.append(row);

                black = !black;
            }

            StringBuilder layer2 = new StringBuilder();
            for (int i = 0; i < layer.length(); i++) {
                if (layer.charAt(i) == 'b') {
                    layer2.append('w');
                } else if (layer.charAt(i) == 'w') {
                    layer2.append('b');
                } else {
                    layer2.append(layer.charAt(i));
                }
            }

            for (int i = 0; i < n; i++) {
                if (i % 2 == 0) {
                    pw.println(layer);
                } else {
                    pw.println(layer2);
                }
            }
        }
    }
}


import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.io.BufferedWriter;
import java.io.Writer;
import java.io.OutputStreamWriter;
import java.util.InputMismatchException;
import java.io.IOException;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author sumit
 */
public class Main {
      public static void main(String[] args) {
            InputStream inputStream = System.in;
            OutputStream outputStream = System.out;
            InputReader in = new InputReader(inputStream);
            OutputWriter out = new OutputWriter(outputStream);
            ABlackAndWhiteCube solver = new ABlackAndWhiteCube();
            solver.solve(1, in, out);
            out.close();
      }

      static class ABlackAndWhiteCube {
            public void solve(int testNumber, InputReader in, OutputWriter out) {
                  int k = in.nextInt();
                  if (k % 2 == 1)
                        out.printLine(-1);
                  else {
                        int mat[][] = new int[k][k];
                        int init = 1;
                        int temp = 0;
                        for (int i = 0; i < k / 2; i++) {
                              for (int j = 0; j < k / 2; j++) {
                                    if (i == 0)
                                          mat[i][j] = init;
                                    else if (j < temp)
                                          mat[i][j] = mat[i - 1][j];
                                    else if (j >= temp) {
                                          mat[i][j] = mat[i - 1][j] ^ 1;
                                    }

                                    mat[k - i - 1][k - j - 1] = mat[i][j];
                                    mat[k - i - 1][j] = mat[i][j];
                                    mat[i][k - j - 1] = mat[i][j];

                              }
                              temp++;

                        }
                        for (int i = 0; i < k; i++)
                              out.printLine(mat[i]);

                        int xor = 1;
                        for (int l = 0; l < k; l++) {

                              for (int i = 0; i < k; i++) {
                                    for (int j = 0; j < k; j++) {
                                          if (xor == 1)
                                                if ((mat[i][j] ^ 1) == 1)
                                                      out.print("b");
                                                else
                                                      out.print("w");
                                          else if (mat[i][j] == 1)
                                                out.print("b");
                                          else
                                                out.print("w");

                                    }
                                    out.printLine();
                              }
                              xor = (xor ^ 1);
                              out.printLine();
                        }
                  }
            }

      }

      static class OutputWriter {
            private final PrintWriter writer;

            public OutputWriter(OutputStream outputStream) {
                  writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream)));
            }

            public OutputWriter(Writer writer) {
                  this.writer = new PrintWriter(writer);
            }

            public void print(Object... objects) {
                  for (int i = 0; i < objects.length; i++) {
                        if (i != 0) {
                              writer.print(' ');
                        }
                        writer.print(objects[i]);
                  }
            }

            public void print(int[] array) {
                  for (int i = 0; i < array.length; i++) {
                        if (i != 0) {
                              writer.print(' ');
                        }
                        writer.print(array[i]);
                  }
            }

            public void printLine(int[] array) {
                  print(array);
                  writer.println();
            }

            public void printLine() {
                  writer.println();
            }

            public void close() {
                  writer.close();
            }

            public void printLine(int i) {
                  writer.println(i);
            }

      }

      static class InputReader {
            private InputStream stream;
            private byte[] buf = new byte[1024];
            private int curChar;
            private int numChars;

            public InputReader(InputStream stream) {
                  this.stream = stream;
            }

            public int read() {
                  if (numChars == -1)
                        throw new InputMismatchException();

                  if (curChar >= numChars) {
                        curChar = 0;
                        try {
                              numChars = stream.read(buf);
                        } catch (IOException e) {
                              throw new InputMismatchException();
                        }
                        if (numChars <= 0)
                              return -1;
                  }

                  return buf[curChar++];
            }

            public int nextInt() {
                  int c = read();

                  while (isSpaceChar(c))
                        c = read();

                  int sgn = 1;

                  if (c == '-') {
                        sgn = -1;
                        c = read();
                  }

                  int res = 0;

                  do {
                        if (c < '0' || c > '9')
                              throw new InputMismatchException();

                        res *= 10;
                        res += c & 15;

                        c = read();
                  } while (!isSpaceChar(c));

                  return res * sgn;
            }

            public boolean isSpaceChar(int c) {
                  return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
            }

      }
}


import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.io.BufferedWriter;
import java.io.Writer;
import java.io.OutputStreamWriter;
import java.util.InputMismatchException;
import java.io.IOException;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author sumit
 */
public class Main {
      public static void main(String[] args) {
            InputStream inputStream = System.in;
            OutputStream outputStream = System.out;
            InputReader in = new InputReader(inputStream);
            OutputWriter out = new OutputWriter(outputStream);
            ABlackAndWhiteCube solver = new ABlackAndWhiteCube();
            solver.solve(1, in, out);
            out.close();
      }

      static class ABlackAndWhiteCube {
            public void solve(int testNumber, InputReader in, OutputWriter out) {
                  int k = in.nextInt();
                  if (k % 2 == 1)
                        out.printLine(-1);
                  else {
                        int mat[][] = new int[k][k];
                        int init = 1;
                        int temp = 0;
                        for (int i = 0; i < k / 2; i++) {
                              for (int j = 0; j < k / 2; j++) {
                                    if (i == 0)
                                          mat[i][j] = init;
                                    else if (j < temp)
                                          mat[i][j] = mat[i - 1][j];
                                    else if (j >= temp) {
                                          mat[i][j] = mat[i - 1][j] ^ 1;
                                    }

                                    mat[k - i - 1][k - j - 1] = mat[i][j];
                                    mat[k - i - 1][j] = mat[i][j];
                                    mat[i][k - j - 1] = mat[i][j];

                              }
                              temp++;

                        }

                        int xor = 1;
                        for (int l = 0; l < k; l++) {

                              for (int i = 0; i < k; i++) {
                                    for (int j = 0; j < k; j++) {
                                          if (xor == 1)
                                                if ((mat[i][j] ^ 1) == 1)
                                                      out.print("b");
                                                else
                                                      out.print("w");
                                          else if (mat[i][j] == 1)
                                                out.print("b");
                                          else
                                                out.print("w");

                                    }
                                    out.printLine();
                              }
                              xor = (xor ^ 1);
                              out.printLine();
                        }
                  }
            }

      }

      static class OutputWriter {
            private final PrintWriter writer;

            public OutputWriter(OutputStream outputStream) {
                  writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream)));
            }

            public OutputWriter(Writer writer) {
                  this.writer = new PrintWriter(writer);
            }

            public void print(Object... objects) {
                  for (int i = 0; i < objects.length; i++) {
                        if (i != 0) {
                              writer.print(' ');
                        }
                        writer.print(objects[i]);
                  }
            }

            public void printLine() {
                  writer.println();
            }

            public void close() {
                  writer.close();
            }

            public void printLine(int i) {
                  writer.println(i);
            }

      }

      static class InputReader {
            private InputStream stream;
            private byte[] buf = new byte[1024];
            private int curChar;
            private int numChars;

            public InputReader(InputStream stream) {
                  this.stream = stream;
            }

            public int read() {
                  if (numChars == -1)
                        throw new InputMismatchException();

                  if (curChar >= numChars) {
                        curChar = 0;
                        try {
                              numChars = stream.read(buf);
                        } catch (IOException e) {
                              throw new InputMismatchException();
                        }
                        if (numChars <= 0)
                              return -1;
                  }

                  return buf[curChar++];
            }

            public int nextInt() {
                  int c = read();

                  while (isSpaceChar(c))
                        c = read();

                  int sgn = 1;

                  if (c == '-') {
                        sgn = -1;
                        c = read();
                  }

                  int res = 0;

                  do {
                        if (c < '0' || c > '9')
                              throw new InputMismatchException();

                        res *= 10;
                        res += c & 15;

                        c = read();
                  } while (!isSpaceChar(c));

                  return res * sgn;
            }

            public boolean isSpaceChar(int c) {
                  return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
            }

      }
}