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

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

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

        cin>>n>>m;
        int arr[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 <iostream>
#include<bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
// #define ONLINE_JUDGE
#ifndef ONLINE_JUDGE
template<typename T>
void __p(T a) {
	cout << a;
}
template<typename T, typename F>
void __p(pair<T, F> a) {
	cout << "{";
	__p(a.first);
	cout << ",";
	__p(a.second);
	cout << "}";
}
template<typename T>
void __p(std::vector<T> a) {
	cout << "{";
	for (auto it = a.begin(); it < a.end(); it++)
		__p(*it), cout << ",}"[it + 1 == a.end()];
}
template<typename T, typename ...Arg>
void __p(T a1, Arg ...a) {
	__p(a1);
	__p(a...);
}
template<typename Arg1>
void __f(const char *name, Arg1 &&arg1) {
	cout << name << " : ";
	__p(arg1);
	cout << endl;
}
template<typename Arg1, typename ... Args>
void __f(const char *names, Arg1 &&arg1, Args &&... args) {
	int bracket = 0, i = 0;
	for (;; i++)
		if (names[i] == ',' && bracket == 0)
			break;
		else if (names[i] == '(')
			bracket++;
		else if (names[i] == ')')
			bracket--;
	const char *comma = names + i;
	cout.write(names, comma - names) << " : ";
	__p(arg1);
	cout << " | ";
	__f(comma + 1, args...);
}
#define trace(...) cout<<"Line:"<<__LINE__<<" ", __f(#__VA_ARGS__, __VA_ARGS__);
#else
#define trace(...)
#endif
typedef long long int ll;
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template <typename T>
using ordered_multiset = tree<T, null_type, less_equal<T>, rb_tree_tag, tree_order_statistics_node_update>;
#define pb(x) push_back(x)
#define mp(x,y) make_pair(x,y)
typedef pair<ll , ll> pp;
typedef pair<pair<ll, ll>, ll> ppp;
#define X first
#define Y second
#define getones(n) __builtin_popcountll(n)
#define debug(x) cout<<#x<<" :: "<<x<<"\n";
#define debug2(x,y) cout<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<"\n";
#define debug3(x,y,z) cout<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<"\t"<<#z<<" :: "<<z<<"\n";
#define fastIO ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define frv(i,a,b) for (ll i = (a), _b = (b); i < _b; i++)
#define frrv(i,a,b) for (ll i = (a), _b = (b); i >= _b; i--)
#define fr(i,n) for (ll i = 0, _n = (n); i < _n; i++)
#define frr(i,n) for (ll i = n - 1; i >= 0; i--)
#define fordata(it,ar) for (auto it = ar.begin(); it != ar.end(); it++)
#define fill(ar,val) fr(i,sizeof(ar)/sizeof(ll)) ar[i]=val
#define fill2(ar,val) fr(i,sizeof(ar)/sizeof(ar[0])) fr(j,sizeof(ar[0])/sizeof(ll)) ar[i][j]=val
#define fill0(ar) memset(ar,0,sizeof(ar))
#define sz(x) (int)x.size()
#define len(x) (int)x.length()
#define all(ar) ar.begin(), ar.end()
#define INF 1000000000000000000
#define PI 3.14159265358979323846L
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
const ll N = 1e6 + 1;
const ll K = 1e9 + 7;
#define vv vector<ll>
const ll globalmod = 1e9 + 9;
ll a[101][101], b[101][101];
ll n, m;
ll dx1[4] = {1, -1, 0, 0};
ll dy1[4] = {0, 0, -1, 1};
bool valid(ll x, ll y) {
	if (x < n && y < m && x >= 0 && y >= 0) {
		return true;
	}
	return false;
}
int main() {
	ll t;
	cin >> t;
	while (t--) {
		cin >> n >> m;
		ll visited[n][m];
		memset(visited, 0, sizeof(visited));
		fr(i, n) {
			fr(j, m) {
				cin >> a[i][j];
				b[i][j] = a[i][j];
			}
		}
		queue<pp> q;
		q.push(mp(0, 0));
		while (!q.empty()) {
			auto p = q.front();
			q.pop();
			auto x = p.X, y = p.Y;
			visited[x][y] = 1;
			trace(x, y)
			bool flag = true;
			fr(i, 4) {
				if (valid(x + dx1[i], y + dy1[i])) {
					// trace(x + dx1[i], y + dy1[i])
					if (b[x + dx1[i]][y + dy1[i]] == b[x][y]) {
						b[x][y]++;
						break;
					}
					if (!visited[x + dx1[i]][y + dy1[i]]) {
						q.push(mp(x + dx1[i], y + dy1[i]));
						visited[x + dx1[i]][y + dy1[i]] = 1;
					}
				}
			}
		}
		fr(i, n) {
			fr(j, m) {
				cout << b[i][j] << " ";
			}
			cout << endl;
		}
	}
}


#include <iostream>
#include<bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
// #define ONLINE_JUDGE
#ifndef ONLINE_JUDGE
template<typename T>
void __p(T a) {
	cout << a;
}
template<typename T, typename F>
void __p(pair<T, F> a) {
	cout << "{";
	__p(a.first);
	cout << ",";
	__p(a.second);
	cout << "}";
}
template<typename T>
void __p(std::vector<T> a) {
	cout << "{";
	for (auto it = a.begin(); it < a.end(); it++)
		__p(*it), cout << ",}"[it + 1 == a.end()];
}
template<typename T, typename ...Arg>
void __p(T a1, Arg ...a) {
	__p(a1);
	__p(a...);
}
template<typename Arg1>
void __f(const char *name, Arg1 &&arg1) {
	cout << name << " : ";
	__p(arg1);
	cout << endl;
}
template<typename Arg1, typename ... Args>
void __f(const char *names, Arg1 &&arg1, Args &&... args) {
	int bracket = 0, i = 0;
	for (;; i++)
		if (names[i] == ',' && bracket == 0)
			break;
		else if (names[i] == '(')
			bracket++;
		else if (names[i] == ')')
			bracket--;
	const char *comma = names + i;
	cout.write(names, comma - names) << " : ";
	__p(arg1);
	cout << " | ";
	__f(comma + 1, args...);
}
#define trace(...) cout<<"Line:"<<__LINE__<<" ", __f(#__VA_ARGS__, __VA_ARGS__);
#else
#define trace(...)
#endif
typedef long long int ll;
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template <typename T>
using ordered_multiset = tree<T, null_type, less_equal<T>, rb_tree_tag, tree_order_statistics_node_update>;
#define pb(x) push_back(x)
#define mp(x,y) make_pair(x,y)
typedef pair<ll , ll> pp;
typedef pair<pair<ll, ll>, ll> ppp;
#define X first
#define Y second
#define getones(n) __builtin_popcountll(n)
#define debug(x) cout<<#x<<" :: "<<x<<"\n";
#define debug2(x,y) cout<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<"\n";
#define debug3(x,y,z) cout<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<"\t"<<#z<<" :: "<<z<<"\n";
#define fastIO ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define frv(i,a,b) for (ll i = (a), _b = (b); i < _b; i++)
#define frrv(i,a,b) for (ll i = (a), _b = (b); i >= _b; i--)
#define fr(i,n) for (ll i = 0, _n = (n); i < _n; i++)
#define frr(i,n) for (ll i = n - 1; i >= 0; i--)
#define fordata(it,ar) for (auto it = ar.begin(); it != ar.end(); it++)
#define fill(ar,val) fr(i,sizeof(ar)/sizeof(ll)) ar[i]=val
#define fill2(ar,val) fr(i,sizeof(ar)/sizeof(ar[0])) fr(j,sizeof(ar[0])/sizeof(ll)) ar[i][j]=val
#define fill0(ar) memset(ar,0,sizeof(ar))
#define sz(x) (int)x.size()
#define len(x) (int)x.length()
#define all(ar) ar.begin(), ar.end()
#define INF 1000000000000000000
#define PI 3.14159265358979323846L
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
const ll N = 1e6 + 1;
const ll K = 1e9 + 7;
#define vv vector<ll>
const ll globalmod = 1e9 + 9;
ll a[101][101], b[101][101];
ll n, m;
ll dx1[4] = {1, -1, 0, 0};
ll dy1[4] = {0, 0, -1, 1};
bool valid(ll x, ll y) {
	if (x < n && y < m && x >= 0 && y >= 0) {
		return true;
	}
	return false;
}
int main() {
	ll t;
	cin >> t;
	while (t--) {
		cin >> n >> m;
		ll visited[n][m];
		memset(visited, 0, sizeof(visited));
		fr(i, n) {
			fr(j, m) {
				cin >> a[i][j];
				b[i][j] = a[i][j];
			}
		}
		queue<pp> q;
		q.push(mp(0, 0));
		while (!q.empty()) {
			auto p = q.front();
			q.pop();
			auto x = p.X, y = p.Y;
			visited[x][y] = 1;
			trace(x, y)
			bool flag = true;
			fr(i, 4) {
				if (valid(x + dx1[i], y + dy1[i])) {
					// trace(x + dx1[i], y + dy1[i])
					if (!visited[x + dx1[i]][y + dy1[i]]) {
						q.push(mp(x + dx1[i], y + dy1[i]));
						visited[x + dx1[i]][y + dy1[i]] = 1;
						if (b[x + dx1[i]][y + dy1[i]] == b[x][y]) {
							b[x][y]++;
							break;
						}
					}
				}
			}
		}
		fr(i, n) {
			fr(j, m) {
				cout << b[i][j] << " ";
			}
			cout << endl;
		}
	}
}


#include <iostream>
#include<bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
// #define ONLINE_JUDGE
#ifndef ONLINE_JUDGE
template<typename T>
void __p(T a) {
	cout << a;
}
template<typename T, typename F>
void __p(pair<T, F> a) {
	cout << "{";
	__p(a.first);
	cout << ",";
	__p(a.second);
	cout << "}";
}
template<typename T>
void __p(std::vector<T> a) {
	cout << "{";
	for (auto it = a.begin(); it < a.end(); it++)
		__p(*it), cout << ",}"[it + 1 == a.end()];
}
template<typename T, typename ...Arg>
void __p(T a1, Arg ...a) {
	__p(a1);
	__p(a...);
}
template<typename Arg1>
void __f(const char *name, Arg1 &&arg1) {
	cout << name << " : ";
	__p(arg1);
	cout << endl;
}
template<typename Arg1, typename ... Args>
void __f(const char *names, Arg1 &&arg1, Args &&... args) {
	int bracket = 0, i = 0;
	for (;; i++)
		if (names[i] == ',' && bracket == 0)
			break;
		else if (names[i] == '(')
			bracket++;
		else if (names[i] == ')')
			bracket--;
	const char *comma = names + i;
	cout.write(names, comma - names) << " : ";
	__p(arg1);
	cout << " | ";
	__f(comma + 1, args...);
}
#define trace(...) cout<<"Line:"<<__LINE__<<" ", __f(#__VA_ARGS__, __VA_ARGS__);
#else
#define trace(...)
#endif
typedef long long int ll;
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template <typename T>
using ordered_multiset = tree<T, null_type, less_equal<T>, rb_tree_tag, tree_order_statistics_node_update>;
#define pb(x) push_back(x)
#define mp(x,y) make_pair(x,y)
typedef pair<ll , ll> pp;
typedef pair<pair<ll, ll>, ll> ppp;
#define X first
#define Y second
#define getones(n) __builtin_popcountll(n)
#define debug(x) cout<<#x<<" :: "<<x<<"\n";
#define debug2(x,y) cout<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<"\n";
#define debug3(x,y,z) cout<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<"\t"<<#z<<" :: "<<z<<"\n";
#define fastIO ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define frv(i,a,b) for (ll i = (a), _b = (b); i < _b; i++)
#define frrv(i,a,b) for (ll i = (a), _b = (b); i >= _b; i--)
#define fr(i,n) for (ll i = 0, _n = (n); i < _n; i++)
#define frr(i,n) for (ll i = n - 1; i >= 0; i--)
#define fordata(it,ar) for (auto it = ar.begin(); it != ar.end(); it++)
#define fill(ar,val) fr(i,sizeof(ar)/sizeof(ll)) ar[i]=val
#define fill2(ar,val) fr(i,sizeof(ar)/sizeof(ar[0])) fr(j,sizeof(ar[0])/sizeof(ll)) ar[i][j]=val
#define fill0(ar) memset(ar,0,sizeof(ar))
#define sz(x) (int)x.size()
#define len(x) (int)x.length()
#define all(ar) ar.begin(), ar.end()
#define INF 1000000000000000000
#define PI 3.14159265358979323846L
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
const ll N = 1e6 + 1;
const ll K = 1e9 + 7;
#define vv vector<ll>
const ll globalmod = 1e9 + 9;
ll a[101][101], b[101][101];
ll n, m;
ll dx1[4] = {1, -1, 0, 0};
ll dy1[4] = {0, 0, -1, 1};
bool valid(ll x, ll y) {
	if (x < n && y < m && x >= 0 && y >= 0) {
		return true;
	}
	return false;
}
int main() {
	ll t;
	cin >> t;
	while (t--) {
		cin >> n >> m;
		ll visited[n][m];
		memset(visited, 0, sizeof(visited));
		fr(i, n) {
			fr(j, m) {
				cin >> a[i][j];
				b[i][j] = a[i][j];
			}
		}
		queue<pp> q;
		q.push(mp(0, 0));
		while (!q.empty()) {
			auto p = q.front();
			q.pop();
			auto x = p.X, y = p.Y;
			visited[x][y] = 1;
			bool flag = true;
			fr(i, 4) {
				if (valid(x + dx1[i], y + dy1[i])) {
					if (!visited[x + dx1[i]][y + dy1[i]])
						q.push(mp(x + dx1[i], y + dy1[i]));
					if (b[x + dx1[i]][y + dy1[i]] == b[x][y] + 1 && !visited[x + dx1[i]][y + dy1[i]]) {
						b[x + dx1[i]][y + dy1[i]]++;
						flag = false;
					}
				}
			}
			if (flag) {
				bool flag1 = false;
				fr(i, 4) {
					if (valid(x + dx1[i], y + dy1[i])) {
						if (b[x + dx1[i]][y + dy1[i]] == b[x][y]) {
							flag1 = true;
						}
					}
				}
				if (flag1)
					b[x][y]++;
			}
		}
		fr(i, n) {
			fr(j, m) {
				cout << b[i][j] << " ";
			}
			cout << endl;
		}
	}
}


#include <iostream>
#include<bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
// #define ONLINE_JUDGE
#ifndef ONLINE_JUDGE
template<typename T>
void __p(T a) {
	cout << a;
}
template<typename T, typename F>
void __p(pair<T, F> a) {
	cout << "{";
	__p(a.first);
	cout << ",";
	__p(a.second);
	cout << "}";
}
template<typename T>
void __p(std::vector<T> a) {
	cout << "{";
	for (auto it = a.begin(); it < a.end(); it++)
		__p(*it), cout << ",}"[it + 1 == a.end()];
}
template<typename T, typename ...Arg>
void __p(T a1, Arg ...a) {
	__p(a1);
	__p(a...);
}
template<typename Arg1>
void __f(const char *name, Arg1 &&arg1) {
	cout << name << " : ";
	__p(arg1);
	cout << endl;
}
template<typename Arg1, typename ... Args>
void __f(const char *names, Arg1 &&arg1, Args &&... args) {
	int bracket = 0, i = 0;
	for (;; i++)
		if (names[i] == ',' && bracket == 0)
			break;
		else if (names[i] == '(')
			bracket++;
		else if (names[i] == ')')
			bracket--;
	const char *comma = names + i;
	cout.write(names, comma - names) << " : ";
	__p(arg1);
	cout << " | ";
	__f(comma + 1, args...);
}
#define trace(...) cout<<"Line:"<<__LINE__<<" ", __f(#__VA_ARGS__, __VA_ARGS__);
#else
#define trace(...)
#endif
typedef long long int ll;
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template <typename T>
using ordered_multiset = tree<T, null_type, less_equal<T>, rb_tree_tag, tree_order_statistics_node_update>;
#define pb(x) push_back(x)
#define mp(x,y) make_pair(x,y)
typedef pair<ll , ll> pp;
typedef pair<pair<ll, ll>, ll> ppp;
#define X first
#define Y second
#define getones(n) __builtin_popcountll(n)
#define debug(x) cout<<#x<<" :: "<<x<<"\n";
#define debug2(x,y) cout<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<"\n";
#define debug3(x,y,z) cout<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<"\t"<<#z<<" :: "<<z<<"\n";
#define fastIO ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define frv(i,a,b) for (ll i = (a), _b = (b); i < _b; i++)
#define frrv(i,a,b) for (ll i = (a), _b = (b); i >= _b; i--)
#define fr(i,n) for (ll i = 0, _n = (n); i < _n; i++)
#define frr(i,n) for (ll i = n - 1; i >= 0; i--)
#define fordata(it,ar) for (auto it = ar.begin(); it != ar.end(); it++)
#define fill(ar,val) fr(i,sizeof(ar)/sizeof(ll)) ar[i]=val
#define fill2(ar,val) fr(i,sizeof(ar)/sizeof(ar[0])) fr(j,sizeof(ar[0])/sizeof(ll)) ar[i][j]=val
#define fill0(ar) memset(ar,0,sizeof(ar))
#define sz(x) (int)x.size()
#define len(x) (int)x.length()
#define all(ar) ar.begin(), ar.end()
#define INF 1000000000000000000
#define PI 3.14159265358979323846L
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
const ll N = 1e6 + 1;
const ll K = 1e9 + 7;
#define vv vector<ll>
const ll globalmod = 1e9 + 9;
ll a[101][101], b[101][101];
ll n, m;
ll dx1[4] = {1, -1, 0, 0};
ll dy1[4] = {0, 0, -1, 1};
bool valid(ll x, ll y) {
	if (x < n && y < m && x >= 0 && y >= 0) {
		return true;
	}
	return false;
}
int main() {
	ll t;
	cin >> t;
	while (t--) {
		cin >> n >> m;
		ll visited[n][m];
		memset(visited, 0, sizeof(visited));
		fr(i, n) {
			fr(j, m) {
				cin >> a[i][j];
				b[i][j] = a[i][j];
			}
		}
		queue<pp> q;
		q.push(mp(0, 0));
		while (!q.empty()) {
			auto p = q.front();
			q.pop();
			auto x = p.X, y = p.Y;
			visited[x][y] = 1;
			trace(x, y)
			bool flag = true;
			fr(i, 4) {
				if (valid(x + dx1[i], y + dy1[i])) {
					// trace(x + dx1[i], y + dy1[i])
					if (b[x + dx1[i]][y + dy1[i]] == b[x][y] && flag) {
						b[x][y]++;
						flag = false;
					}
					if (!visited[x + dx1[i]][y + dy1[i]]) {
						q.push(mp(x + dx1[i], y + dy1[i]));
						visited[x + dx1[i]][y + dy1[i]] = 1;
					}
				}
			}
		}
		fr(i, n) {
			fr(j, m) {
				cout << b[i][j] << " ";
			}
			cout << endl;
		}
	}
}


#include <iostream>
#include<bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
// #define ONLINE_JUDGE
#ifndef ONLINE_JUDGE
template<typename T>
void __p(T a) {
	cout << a;
}
template<typename T, typename F>
void __p(pair<T, F> a) {
	cout << "{";
	__p(a.first);
	cout << ",";
	__p(a.second);
	cout << "}";
}
template<typename T>
void __p(std::vector<T> a) {
	cout << "{";
	for (auto it = a.begin(); it < a.end(); it++)
		__p(*it), cout << ",}"[it + 1 == a.end()];
}
template<typename T, typename ...Arg>
void __p(T a1, Arg ...a) {
	__p(a1);
	__p(a...);
}
template<typename Arg1>
void __f(const char *name, Arg1 &&arg1) {
	cout << name << " : ";
	__p(arg1);
	cout << endl;
}
template<typename Arg1, typename ... Args>
void __f(const char *names, Arg1 &&arg1, Args &&... args) {
	int bracket = 0, i = 0;
	for (;; i++)
		if (names[i] == ',' && bracket == 0)
			break;
		else if (names[i] == '(')
			bracket++;
		else if (names[i] == ')')
			bracket--;
	const char *comma = names + i;
	cout.write(names, comma - names) << " : ";
	__p(arg1);
	cout << " | ";
	__f(comma + 1, args...);
}
#define trace(...) cout<<"Line:"<<__LINE__<<" ", __f(#__VA_ARGS__, __VA_ARGS__);
#else
#define trace(...)
#endif
typedef long long int ll;
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template <typename T>
using ordered_multiset = tree<T, null_type, less_equal<T>, rb_tree_tag, tree_order_statistics_node_update>;
#define pb(x) push_back(x)
#define mp(x,y) make_pair(x,y)
typedef pair<ll , ll> pp;
typedef pair<pair<ll, ll>, ll> ppp;
#define X first
#define Y second
#define getones(n) __builtin_popcountll(n)
#define debug(x) cout<<#x<<" :: "<<x<<"\n";
#define debug2(x,y) cout<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<"\n";
#define debug3(x,y,z) cout<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<"\t"<<#z<<" :: "<<z<<"\n";
#define fastIO ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define frv(i,a,b) for (ll i = (a), _b = (b); i < _b; i++)
#define frrv(i,a,b) for (ll i = (a), _b = (b); i >= _b; i--)
#define fr(i,n) for (ll i = 0, _n = (n); i < _n; i++)
#define frr(i,n) for (ll i = n - 1; i >= 0; i--)
#define fordata(it,ar) for (auto it = ar.begin(); it != ar.end(); it++)
#define fill(ar,val) fr(i,sizeof(ar)/sizeof(ll)) ar[i]=val
#define fill2(ar,val) fr(i,sizeof(ar)/sizeof(ar[0])) fr(j,sizeof(ar[0])/sizeof(ll)) ar[i][j]=val
#define fill0(ar) memset(ar,0,sizeof(ar))
#define sz(x) (int)x.size()
#define len(x) (int)x.length()
#define all(ar) ar.begin(), ar.end()
#define INF 1000000000000000000
#define PI 3.14159265358979323846L
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
const ll N = 1e6 + 1;
const ll K = 1e9 + 7;
#define vv vector<ll>
const ll globalmod = 1e9 + 9;
ll a[101][101], b[101][101];
ll n, m;
ll dx1[4] = {1, -1, 0, 0};
ll dy1[4] = {0, 0, -1, 1};
bool valid(ll x, ll y) {
	if (x < n && y < m && x >= 0 && y >= 0) {
		return true;
	}
	return false;
}
int main() {
	ll t;
	cin >> t;
	while (t--) {
		cin >> n >> m;
		ll visited[n][m];
		memset(visited, 0, sizeof(visited));
		fr(i, n) {
			fr(j, m) {
				cin >> a[i][j];
				b[i][j] = a[i][j];
			}
		}
		queue<pp> q;
		q.push(mp(0, 0));
		while (!q.empty()) {
			auto p = q.front();
			q.pop();
			auto x = p.X, y = p.Y;
			visited[x][y] = 1;
			bool flag = true;
			fr(i, 4) {
				if (valid(x + dx1[i], y + dy1[i])) {
					// trace(x + dx1[i], y + dy1[i])
					if (!visited[x + dx1[i]][y + dy1[i]]) {
						q.push(mp(x + dx1[i], y + dy1[i]));
						if (b[x + dx1[i]][y + dy1[i]] == b[x][y]) {
							b[x][y]++;
							break;
						}
					}
				}
			}
		}
		fr(i, n) {
			fr(j, m) {
				cout << b[i][j] << " ";
			}
			cout << endl;
		}
	}
}


#include <iostream>
#include<bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
// #define ONLINE_JUDGE
#ifndef ONLINE_JUDGE
template<typename T>
void __p(T a) {
	cout << a;
}
template<typename T, typename F>
void __p(pair<T, F> a) {
	cout << "{";
	__p(a.first);
	cout << ",";
	__p(a.second);
	cout << "}";
}
template<typename T>
void __p(std::vector<T> a) {
	cout << "{";
	for (auto it = a.begin(); it < a.end(); it++)
		__p(*it), cout << ",}"[it + 1 == a.end()];
}
template<typename T, typename ...Arg>
void __p(T a1, Arg ...a) {
	__p(a1);
	__p(a...);
}
template<typename Arg1>
void __f(const char *name, Arg1 &&arg1) {
	cout << name << " : ";
	__p(arg1);
	cout << endl;
}
template<typename Arg1, typename ... Args>
void __f(const char *names, Arg1 &&arg1, Args &&... args) {
	int bracket = 0, i = 0;
	for (;; i++)
		if (names[i] == ',' && bracket == 0)
			break;
		else if (names[i] == '(')
			bracket++;
		else if (names[i] == ')')
			bracket--;
	const char *comma = names + i;
	cout.write(names, comma - names) << " : ";
	__p(arg1);
	cout << " | ";
	__f(comma + 1, args...);
}
#define trace(...) cout<<"Line:"<<__LINE__<<" ", __f(#__VA_ARGS__, __VA_ARGS__);
#else
#define trace(...)
#endif
typedef long long int ll;
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template <typename T>
using ordered_multiset = tree<T, null_type, less_equal<T>, rb_tree_tag, tree_order_statistics_node_update>;
#define pb(x) push_back(x)
#define mp(x,y) make_pair(x,y)
typedef pair<ll , ll> pp;
typedef pair<pair<ll, ll>, ll> ppp;
#define X first
#define Y second
#define getones(n) __builtin_popcountll(n)
#define debug(x) cout<<#x<<" :: "<<x<<"\n";
#define debug2(x,y) cout<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<"\n";
#define debug3(x,y,z) cout<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<"\t"<<#z<<" :: "<<z<<"\n";
#define fastIO ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define frv(i,a,b) for (ll i = (a), _b = (b); i < _b; i++)
#define frrv(i,a,b) for (ll i = (a), _b = (b); i >= _b; i--)
#define fr(i,n) for (ll i = 0, _n = (n); i < _n; i++)
#define frr(i,n) for (ll i = n - 1; i >= 0; i--)
#define fordata(it,ar) for (auto it = ar.begin(); it != ar.end(); it++)
#define fill(ar,val) fr(i,sizeof(ar)/sizeof(ll)) ar[i]=val
#define fill2(ar,val) fr(i,sizeof(ar)/sizeof(ar[0])) fr(j,sizeof(ar[0])/sizeof(ll)) ar[i][j]=val
#define fill0(ar) memset(ar,0,sizeof(ar))
#define sz(x) (int)x.size()
#define len(x) (int)x.length()
#define all(ar) ar.begin(), ar.end()
#define INF 1000000000000000000
#define PI 3.14159265358979323846L
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
const ll N = 1e6 + 1;
const ll K = 1e9 + 7;
#define vv vector<ll>
const ll globalmod = 1e9 + 9;
ll a[101][101], b[101][101];
ll n, m;
ll dx1[4] = {1, -1, 0, 0};
ll dy1[4] = {0, 0, -1, 1};
bool valid(ll x, ll y) {
	if (x < n && y < m && x >= 0 && y >= 0) {
		return true;
	}
	return false;
}
int main() {
	ll t;
	cin >> t;
	while (t--) {
		cin >> n >> m;
		ll visited[n][m];
		memset(visited, 0, sizeof(visited));
		fr(i, n) {
			fr(j, m) {
				cin >> a[i][j];
				b[i][j] = a[i][j];
			}
		}
		queue<pp> q;
		q.push(mp(0, 0));
		while (!q.empty()) {
			auto p = q.front();
			q.pop();
			auto x = p.X, y = p.Y;
			visited[x][y] = 1;
			trace(x, y)
			bool flag = true;
			fr(i, 4) {
				if (valid(x + dx1[i], y + dy1[i])) {
					if (b[x + dx1[i]][y + dy1[i]] == b[x][y] + 1) {
						flag = false;
					}
				}
			}
			fr(i, 4) {
				if (valid(x + dx1[i], y + dy1[i])) {
					// trace(x + dx1[i], y + dy1[i])
					if (b[x + dx1[i]][y + dy1[i]] == b[x][y] && flag) {
						b[x][y]++;
						flag = false;
					}
					if (!visited[x + dx1[i]][y + dy1[i]]) {
						q.push(mp(x + dx1[i], y + dy1[i]));
						visited[x + dx1[i]][y + dy1[i]] = 1;
					}
				}
			}
		}
		fr(i, n) {
			fr(j, m) {
				cout << b[i][j] << " ";
			}
			cout << endl;
		}
	}
}


#include <iostream>
#include<bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
// #define ONLINE_JUDGE
#ifndef ONLINE_JUDGE
template<typename T>
void __p(T a) {
	cout << a;
}
template<typename T, typename F>
void __p(pair<T, F> a) {
	cout << "{";
	__p(a.first);
	cout << ",";
	__p(a.second);
	cout << "}";
}
template<typename T>
void __p(std::vector<T> a) {
	cout << "{";
	for (auto it = a.begin(); it < a.end(); it++)
		__p(*it), cout << ",}"[it + 1 == a.end()];
}
template<typename T, typename ...Arg>
void __p(T a1, Arg ...a) {
	__p(a1);
	__p(a...);
}
template<typename Arg1>
void __f(const char *name, Arg1 &&arg1) {
	cout << name << " : ";
	__p(arg1);
	cout << endl;
}
template<typename Arg1, typename ... Args>
void __f(const char *names, Arg1 &&arg1, Args &&... args) {
	int bracket = 0, i = 0;
	for (;; i++)
		if (names[i] == ',' && bracket == 0)
			break;
		else if (names[i] == '(')
			bracket++;
		else if (names[i] == ')')
			bracket--;
	const char *comma = names + i;
	cout.write(names, comma - names) << " : ";
	__p(arg1);
	cout << " | ";
	__f(comma + 1, args...);
}
#define trace(...) cout<<"Line:"<<__LINE__<<" ", __f(#__VA_ARGS__, __VA_ARGS__);
#else
#define trace(...)
#endif
typedef long long int ll;
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template <typename T>
using ordered_multiset = tree<T, null_type, less_equal<T>, rb_tree_tag, tree_order_statistics_node_update>;
#define pb(x) push_back(x)
#define mp(x,y) make_pair(x,y)
typedef pair<ll , ll> pp;
typedef pair<pair<ll, ll>, ll> ppp;
#define X first
#define Y second
#define getones(n) __builtin_popcountll(n)
#define debug(x) cout<<#x<<" :: "<<x<<"\n";
#define debug2(x,y) cout<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<"\n";
#define debug3(x,y,z) cout<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<"\t"<<#z<<" :: "<<z<<"\n";
#define fastIO ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define frv(i,a,b) for (ll i = (a), _b = (b); i < _b; i++)
#define frrv(i,a,b) for (ll i = (a), _b = (b); i >= _b; i--)
#define fr(i,n) for (ll i = 0, _n = (n); i < _n; i++)
#define frr(i,n) for (ll i = n - 1; i >= 0; i--)
#define fordata(it,ar) for (auto it = ar.begin(); it != ar.end(); it++)
#define fill(ar,val) fr(i,sizeof(ar)/sizeof(ll)) ar[i]=val
#define fill2(ar,val) fr(i,sizeof(ar)/sizeof(ar[0])) fr(j,sizeof(ar[0])/sizeof(ll)) ar[i][j]=val
#define fill0(ar) memset(ar,0,sizeof(ar))
#define sz(x) (int)x.size()
#define len(x) (int)x.length()
#define all(ar) ar.begin(), ar.end()
#define INF 1000000000000000000
#define PI 3.14159265358979323846L
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
const ll N = 1e6 + 1;
const ll K = 1e9 + 7;
#define vv vector<ll>
const ll globalmod = 1e9 + 9;
ll a[101][101], b[101][101];
ll n, m;
ll dx1[4] = {1, -1, 0, 0};
ll dy1[4] = {0, 0, -1, 1};
bool valid(ll x, ll y) {
	if (x < n && y < m && x >= 0 && y >= 0) {
		return true;
	}
	return false;
}
int main() {
	ll t;
	cin >> t;
	while (t--) {
		cin >> n >> m;
		ll visited[n][m];
		memset(visited, 0, sizeof(visited));
		fr(i, n) {
			fr(j, m) {
				cin >> a[i][j];
				b[i][j] = a[i][j];
			}
		}
		queue<pp> q;
		q.push(mp(0, 0));
		while (!q.empty()) {
			auto p = q.front();
			q.pop();
			auto x = p.X, y = p.Y;
			visited[x][y] = 1;
			trace(x, y)
			bool flag = true, flag1 = true;
			fr(i, 4) {
				if (valid(x + dx1[i], y + dy1[i])) {
					if (b[x + dx1[i]][y + dy1[i]] == b[x][y] + 1) {
						flag1 = false;
					}
				}
			}
			if (!flag1) {
				fr(i, 4) {
					if (valid(x + dx1[i], y + dy1[i])) {
						if (b[x + dx1[i]][y + dy1[i]] == b[x][y]) {
							b[x + dx1[i]][y + dy1[i]]++;
						}
						if (!visited[x + dx1[i]][y + dy1[i]]) {
							q.push(mp(x + dx1[i], y + dy1[i]));
							visited[x + dx1[i]][y + dy1[i]] = 1;
						}
					}
				}
				continue;
			}
			fr(i, 4) {
				if (valid(x + dx1[i], y + dy1[i]) && flag1) {
					// trace(x + dx1[i], y + dy1[i])
					if (b[x + dx1[i]][y + dy1[i]] == b[x][y] && flag) {
						b[x][y]++;
						flag = false;
					}
					if (!visited[x + dx1[i]][y + dy1[i]]) {
						q.push(mp(x + dx1[i], y + dy1[i]));
						visited[x + dx1[i]][y + dy1[i]] = 1;
					}
				}
			}
		}
		fr(i, n) {
			fr(j, m) {
				cout << b[i][j] << " ";
			}
			cout << endl;
		}
	}
}


#include <iostream>
#include<bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
// #define ONLINE_JUDGE
#ifndef ONLINE_JUDGE
template<typename T>
void __p(T a) {
	cout << a;
}
template<typename T, typename F>
void __p(pair<T, F> a) {
	cout << "{";
	__p(a.first);
	cout << ",";
	__p(a.second);
	cout << "}";
}
template<typename T>
void __p(std::vector<T> a) {
	cout << "{";
	for (auto it = a.begin(); it < a.end(); it++)
		__p(*it), cout << ",}"[it + 1 == a.end()];
}
template<typename T, typename ...Arg>
void __p(T a1, Arg ...a) {
	__p(a1);
	__p(a...);
}
template<typename Arg1>
void __f(const char *name, Arg1 &&arg1) {
	cout << name << " : ";
	__p(arg1);
	cout << endl;
}
template<typename Arg1, typename ... Args>
void __f(const char *names, Arg1 &&arg1, Args &&... args) {
	int bracket = 0, i = 0;
	for (;; i++)
		if (names[i] == ',' && bracket == 0)
			break;
		else if (names[i] == '(')
			bracket++;
		else if (names[i] == ')')
			bracket--;
	const char *comma = names + i;
	cout.write(names, comma - names) << " : ";
	__p(arg1);
	cout << " | ";
	__f(comma + 1, args...);
}
#define trace(...) cout<<"Line:"<<__LINE__<<" ", __f(#__VA_ARGS__, __VA_ARGS__);
#else
#define trace(...)
#endif
typedef long long int ll;
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template <typename T>
using ordered_multiset = tree<T, null_type, less_equal<T>, rb_tree_tag, tree_order_statistics_node_update>;
#define pb(x) push_back(x)
#define mp(x,y) make_pair(x,y)
typedef pair<ll , ll> pp;
typedef pair<pair<ll, ll>, ll> ppp;
#define X first
#define Y second
#define getones(n) __builtin_popcountll(n)
#define debug(x) cout<<#x<<" :: "<<x<<"\n";
#define debug2(x,y) cout<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<"\n";
#define debug3(x,y,z) cout<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<"\t"<<#z<<" :: "<<z<<"\n";
#define fastIO ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define frv(i,a,b) for (ll i = (a), _b = (b); i < _b; i++)
#define frrv(i,a,b) for (ll i = (a), _b = (b); i >= _b; i--)
#define fr(i,n) for (ll i = 0, _n = (n); i < _n; i++)
#define frr(i,n) for (ll i = n - 1; i >= 0; i--)
#define fordata(it,ar) for (auto it = ar.begin(); it != ar.end(); it++)
#define fill(ar,val) fr(i,sizeof(ar)/sizeof(ll)) ar[i]=val
#define fill2(ar,val) fr(i,sizeof(ar)/sizeof(ar[0])) fr(j,sizeof(ar[0])/sizeof(ll)) ar[i][j]=val
#define fill0(ar) memset(ar,0,sizeof(ar))
#define sz(x) (int)x.size()
#define len(x) (int)x.length()
#define all(ar) ar.begin(), ar.end()
#define INF 1000000000000000000
#define PI 3.14159265358979323846L
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
const ll N = 1e6 + 1;
const ll K = 1e9 + 7;
#define vv vector<ll>
const ll globalmod = 1e9 + 9;
ll a[101][101], b[101][101];
ll n, m;
ll dx1[4] = {1, -1, 0, 0};
ll dy1[4] = {0, 0, -1, 1};
int main() {
	ll t;
	cin >> t;
	while (t--) {
		cin >> n >> m;
		fr(i, n) {
			fr(j, m) {
				cin >> a[i][j];
				if (a[i][j] % 2 != (i + j) % 2) {
					a[i][j]++;
				}
			}
		}
		fr(i, n) {
			fr(j, m) {
				cout << a[i][j] << " ";
			}
			cout << endl;
		}
	}
}


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

using   ll        = long long int;
using   pll       = pair<ll, ll>;
using   vll       = vector<ll>;
ll const max_size = 1024;
ll const mod      = 1e9 + 7;
ll const maxn     = 1e5 + 1;
#define endl        "\n"
#define ssp         " "
#define n_l         cout<<"\n"
#define TLE_na_ho   ios_base::sync_with_stdio(false);cin.tie(NULL)
#define pb          push_back
#define ff          first
#define ss          second
#define all(v)      v.begin(),v.end()
#define f(n)        for(ll i=0;i<n;i++)
#define rep(i,a,n)  for(ll i=a;i<n;i++)
#define repe(i,a,n) for(ll i=a;i<=n;i++)
#define repr(i,a,n) for(ll i=a;i>=n;i--)
#define ain(arr,n)  for(ll i1=0;i1<n;i1++ ) cin>>arr[i1]
#define aout(arr,n) for(ll i1=0;i1<n;i1++ ) cout<<arr[i1]<<ssp

/*
░█▀▀▄ ░█▀▀▀ ░█▀▀█ ░█─░█ ░█▀▀█
░█─░█ ░█▀▀▀ ░█▀▀▄ ░█─░█ ░█─▄▄
░█▄▄▀ ░█▄▄▄ ░█▄▄█ ─▀▄▄▀ ░█▄▄█*/
void __print(int x)
{
    cerr << x;
}
void __print(long x)
{
    cerr << x;
}
void __print(long long x)
{
    cerr << x;
}
void __print(unsigned x)
{
    cerr << x;
}
void __print(unsigned long x)
{
    cerr << x;
}
void __print(unsigned long long x)
{
    cerr << x;
}
void __print(float x)
{
    cerr << x;
}
void __print(double x)
{
    cerr << x;
}
void __print(long double x)
{
    cerr << x;
}
void __print(char x)
{
    cerr << '\'' << x << '\'';
}
void __print(const char *x)
{
    cerr << '\"' << x << '\"';
}
void __print(const string &x)
{
    cerr << '\"' << x << '\"';
}
void __print(bool x)
{
    cerr << (x ? "true" : "false");
}

template<typename T, typename V>
void __print(const pair<T, V> &x)
{
    cerr << '{';
    __print(x.first);
    cerr << ',';
    __print(x.second);
    cerr << '}';
}
template<typename T>
void __print(const T &x)
{
    int f = 0;
    cerr << '{';
    for (auto &i : x) cerr << (f++ ? "," : ""), __print(i);
    cerr << "}";
}
void _print()
{
    cerr << "]\n";
}
template <typename T, typename... V>
void _print(T t, V... v)
{
    __print(t);
    if (sizeof...(v)) cerr << ", ";
    _print(v...);
}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif
/*
░█▀▀▄ ░█▀▀▀ ░█▀▀█ ░█─░█ ░█▀▀█
░█─░█ ░█▀▀▀ ░█▀▀▄ ░█─░█ ░█─▄▄
░█▄▄▀ ░█▄▄▄ ░█▄▄█ ─▀▄▄▀ ░█▄▄█*/

ll testcases;

int main()
{
    TLE_na_ho;
    //READ THE QUESTION PROPERLY!!
    //testcases=1;
    cin >> testcases;
    while(testcases--)
    {
        ll n, m;
        cin >> n >> m;
        ll a[n][m];
        f(n)
        rep(j, 0, m)
        cin >> a[i][j];
        map<ll, ll> cnt;
        bool f[n][m] = {0};
        for(ll i = 0; i < n; i++)
        {
            for(ll j = 0; j < m; j++)
            {
                if( j > 0 && f[i][j] == 0 && f[i][j - 1] == 0 && a[i][j] == a[i][j - 1])
                {
                    cnt[a[i][j]]++;
                    f[i][j] = 1;
                    f[i][j - 1] = 1;

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

                }
                if( j < n - f[i][j] == 0 && f[i][j + 1] == 0 && 1 && a[i][j] == a[i][j + 1])
                {
                    cnt[a[i][j]]++;
                    f[i][j] = 1;
                    f[i][j + 1] = 1;

                }
                if( i < n - f[i][j] == 0 && f[i + 1][j] == 0 && 1 && a[i][j] == a[i + 1][j])
                {
                    cnt[a[i][j]]++;
                    f[i][j] = 1;
                    f[i + 1][j] = 1;
                }
            }
        }

        for(ll i = 0; i < n; i++)
        {
            for(ll j = 0; j < m; j++)
            {
                if(cnt[a[i][j]] > 0)
                {
                    cnt[a[i][j]]--;
                    a[i][j]++;
                }
            }
        }

        for(ll i = 0; i < n; i++)
        {
            for(ll j = 0; j < m; j++)
                cout << a[i][j] << ssp;
            cout << endl;
        }
    }

}


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

using   ll        = long long int;
using   pll       = pair<ll, ll>;
using   vll       = vector<ll>;
ll const max_size = 1024;
ll const mod      = 1e9 + 7;
ll const maxn     = 1e5 + 1;
#define endl        "\n"
#define ssp         " "
#define n_l         cout<<"\n"
#define TLE_na_ho   ios_base::sync_with_stdio(false);cin.tie(NULL)
#define pb          push_back
#define ff          first
#define ss          second
#define all(v)      v.begin(),v.end()
#define f(n)        for(ll i=0;i<n;i++)
#define rep(i,a,n)  for(ll i=a;i<n;i++)
#define repe(i,a,n) for(ll i=a;i<=n;i++)
#define repr(i,a,n) for(ll i=a;i>=n;i--)
#define ain(arr,n)  for(ll i1=0;i1<n;i1++ ) cin>>arr[i1]
#define aout(arr,n) for(ll i1=0;i1<n;i1++ ) cout<<arr[i1]<<ssp

/*
░█▀▀▄ ░█▀▀▀ ░█▀▀█ ░█─░█ ░█▀▀█
░█─░█ ░█▀▀▀ ░█▀▀▄ ░█─░█ ░█─▄▄
░█▄▄▀ ░█▄▄▄ ░█▄▄█ ─▀▄▄▀ ░█▄▄█*/
void __print(int x)
{
    cerr << x;
}
void __print(long x)
{
    cerr << x;
}
void __print(long long x)
{
    cerr << x;
}
void __print(unsigned x)
{
    cerr << x;
}
void __print(unsigned long x)
{
    cerr << x;
}
void __print(unsigned long long x)
{
    cerr << x;
}
void __print(float x)
{
    cerr << x;
}
void __print(double x)
{
    cerr << x;
}
void __print(long double x)
{
    cerr << x;
}
void __print(char x)
{
    cerr << '\'' << x << '\'';
}
void __print(const char *x)
{
    cerr << '\"' << x << '\"';
}
void __print(const string &x)
{
    cerr << '\"' << x << '\"';
}
void __print(bool x)
{
    cerr << (x ? "true" : "false");
}

template<typename T, typename V>
void __print(const pair<T, V> &x)
{
    cerr << '{';
    __print(x.first);
    cerr << ',';
    __print(x.second);
    cerr << '}';
}
template<typename T>
void __print(const T &x)
{
    int f = 0;
    cerr << '{';
    for (auto &i : x) cerr << (f++ ? "," : ""), __print(i);
    cerr << "}";
}
void _print()
{
    cerr << "]\n";
}
template <typename T, typename... V>
void _print(T t, V... v)
{
    __print(t);
    if (sizeof...(v)) cerr << ", ";
    _print(v...);
}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif
/*
░█▀▀▄ ░█▀▀▀ ░█▀▀█ ░█─░█ ░█▀▀█
░█─░█ ░█▀▀▀ ░█▀▀▄ ░█─░█ ░█─▄▄
░█▄▄▀ ░█▄▄▄ ░█▄▄█ ─▀▄▄▀ ░█▄▄█*/

ll testcases;

int main()
{
    TLE_na_ho;
    //READ THE QUESTION PROPERLY!!
    //testcases=1;
    cin >> testcases;
    while(testcases--)
    {
        ll n, m;
        cin >> n >> m;
        ll a[n][m];
        f(n)
        rep(j, 0, m)
        cin >> a[i][j];
        map<ll, ll> cnt;
        bool f[n][m] = {0};
        for(ll i = 0; i < n; i++)
        {
            for(ll j = 0; j < n; j++)
            {
                if( j > 0 && f[i][j] == 0 && f[i][j - 1] == 0 && a[i][j] == a[i][j - 1])
                {
                    cnt[a[i][j]]++;
                    f[i][j] = 1;
                    //f[i][j - 1] = 1;

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

                }
                if( j < n - f[i][j] == 0 && f[i][j + 1] == 0 && 1 && a[i][j] == a[i][j + 1])
                {
                    cnt[a[i][j]]++;
                    f[i][j] = 1;
                    //f[i][j + 1] = 1;

                }
                if( i < n - f[i][j] == 0 && f[i + 1][j] == 0 && 1 && a[i][j] == a[i + 1][j])
                {
                    cnt[a[i][j]]++;
                    f[i][j] = 1;
                    //f[i + 1][j] = 1;
                }
            }
        }

        for(ll i = 0; i < n; i++)
        {
            for(ll j = 0; j < n; j++)
            {
                if(cnt[a[i][j]] > 0)
                {
                    cnt[a[i][j]]--;
                    a[i][j]++;
                }
            }
        }

        for(ll i = 0; i < n; i++)
        {
            for(ll j = 0; j < m; j++)
                cout << a[i][j] << ssp;
            cout << endl;
        }
    }

}


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

using   ll        = long long int;
using   pll       = pair<ll, ll>;
using   vll       = vector<ll>;
ll const max_size = 1024;
ll const mod      = 1e9 + 7;
ll const maxn     = 1e5 + 1;
#define endl        "\n"
#define ssp         " "
#define n_l         cout<<"\n"
#define TLE_na_ho   ios_base::sync_with_stdio(false);cin.tie(NULL)
#define pb          push_back
#define ff          first
#define ss          second
#define all(v)      v.begin(),v.end()
#define f(n)        for(ll i=0;i<n;i++)
#define rep(i,a,n)  for(ll i=a;i<n;i++)
#define repe(i,a,n) for(ll i=a;i<=n;i++)
#define repr(i,a,n) for(ll i=a;i>=n;i--)
#define ain(arr,n)  for(ll i1=0;i1<n;i1++ ) cin>>arr[i1]
#define aout(arr,n) for(ll i1=0;i1<n;i1++ ) cout<<arr[i1]<<ssp

/*
░█▀▀▄ ░█▀▀▀ ░█▀▀█ ░█─░█ ░█▀▀█
░█─░█ ░█▀▀▀ ░█▀▀▄ ░█─░█ ░█─▄▄
░█▄▄▀ ░█▄▄▄ ░█▄▄█ ─▀▄▄▀ ░█▄▄█*/
void __print(int x)
{
    cerr << x;
}
void __print(long x)
{
    cerr << x;
}
void __print(long long x)
{
    cerr << x;
}
void __print(unsigned x)
{
    cerr << x;
}
void __print(unsigned long x)
{
    cerr << x;
}
void __print(unsigned long long x)
{
    cerr << x;
}
void __print(float x)
{
    cerr << x;
}
void __print(double x)
{
    cerr << x;
}
void __print(long double x)
{
    cerr << x;
}
void __print(char x)
{
    cerr << '\'' << x << '\'';
}
void __print(const char *x)
{
    cerr << '\"' << x << '\"';
}
void __print(const string &x)
{
    cerr << '\"' << x << '\"';
}
void __print(bool x)
{
    cerr << (x ? "true" : "false");
}

template<typename T, typename V>
void __print(const pair<T, V> &x)
{
    cerr << '{';
    __print(x.first);
    cerr << ',';
    __print(x.second);
    cerr << '}';
}
template<typename T>
void __print(const T &x)
{
    int f = 0;
    cerr << '{';
    for (auto &i : x) cerr << (f++ ? "," : ""), __print(i);
    cerr << "}";
}
void _print()
{
    cerr << "]\n";
}
template <typename T, typename... V>
void _print(T t, V... v)
{
    __print(t);
    if (sizeof...(v)) cerr << ", ";
    _print(v...);
}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif
/*
░█▀▀▄ ░█▀▀▀ ░█▀▀█ ░█─░█ ░█▀▀█
░█─░█ ░█▀▀▀ ░█▀▀▄ ░█─░█ ░█─▄▄
░█▄▄▀ ░█▄▄▄ ░█▄▄█ ─▀▄▄▀ ░█▄▄█*/

ll testcases;

int main()
{
    TLE_na_ho;
    //READ THE QUESTION PROPERLY!!
    //testcases=1;
    cin >> testcases;
    while(testcases--)
    {
        ll n, m;
        cin >> n >> m;
        ll a[n][m];
        f(n)
        rep(j, 0, m)
        cin >> a[i][j];
        bool f[n][m] = {0};
        for(ll i = 0; i < n; i++)
        {
            for(ll j = 0; j < m; j++)
            {
                if(i == j)
                {
                    if( j > 0 && a[i][j] == a[i][j - 1])
                    {
                        if(f[i][j] == 0)
                        {
                            a[i][j]++;
                            f[i][j] = 1;
                        }
                        else if(f[i][j - 1] == 0)
                        {
                            a[i][j - 1]++;
                            f[i][j - 1] = 1;
                        }
                    }
                    if( i > 0 && a[i][j] == a[i - 1][j])
                    {
                        if(f[i][j] == 0)
                        {
                            a[i][j]++;
                            f[i][j] = 1;
                        }
                        else if(f[i - 1][j] == 0)
                        {
                            a[i - 1][j]++;
                            f[i - 1][j] = 1;
                        }
                    }
                    if( j < n && a[i][j] == a[i][j + 1])
                    {
                        if(f[i][j] == 0)
                        {
                            a[i][j]++;
                            f[i][j] = 1;
                        }
                        else if(f[i][j + 1] == 0)
                        {
                            a[i][j + 1]++;
                            f[i][j + 1] = 1;
                        }
                    }
                    if( i < n && a[i][j] == a[i + 1][j])
                    {
                        if(f[i][j] == 0)
                        {
                            a[i][j]++;
                            f[i][j] = 1;
                        }
                        else if(f[i + 1][j] == 0)
                        {
                            a[i + 1][j]++;
                            f[i + 1][j] = 1;
                        }
                    }
                }
            }
        }

        for(ll i = 0; i < n; i++)
        {
            for(ll j = 0; j < m; j++)
                cout << a[i][j] << ssp;
            cout << endl;
        }
    }

}


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

using   ll        = long long int;
using   pll       = pair<ll, ll>;
using   vll       = vector<ll>;
ll const max_size = 1024;
ll const mod      = 1e9 + 7;
ll const maxn     = 1e5 + 1;
#define endl        "\n"
#define ssp         " "
#define n_l         cout<<"\n"
#define TLE_na_ho   ios_base::sync_with_stdio(false);cin.tie(NULL)
#define pb          push_back
#define ff          first
#define ss          second
#define all(v)      v.begin(),v.end()
#define f(n)        for(ll i=0;i<n;i++)
#define rep(i,a,n)  for(ll i=a;i<n;i++)
#define repe(i,a,n) for(ll i=a;i<=n;i++)
#define repr(i,a,n) for(ll i=a;i>=n;i--)
#define ain(arr,n)  for(ll i1=0;i1<n;i1++ ) cin>>arr[i1]
#define aout(arr,n) for(ll i1=0;i1<n;i1++ ) cout<<arr[i1]<<ssp

/*
░█▀▀▄ ░█▀▀▀ ░█▀▀█ ░█─░█ ░█▀▀█
░█─░█ ░█▀▀▀ ░█▀▀▄ ░█─░█ ░█─▄▄
░█▄▄▀ ░█▄▄▄ ░█▄▄█ ─▀▄▄▀ ░█▄▄█*/
void __print(int x)
{
    cerr << x;
}
void __print(long x)
{
    cerr << x;
}
void __print(long long x)
{
    cerr << x;
}
void __print(unsigned x)
{
    cerr << x;
}
void __print(unsigned long x)
{
    cerr << x;
}
void __print(unsigned long long x)
{
    cerr << x;
}
void __print(float x)
{
    cerr << x;
}
void __print(double x)
{
    cerr << x;
}
void __print(long double x)
{
    cerr << x;
}
void __print(char x)
{
    cerr << '\'' << x << '\'';
}
void __print(const char *x)
{
    cerr << '\"' << x << '\"';
}
void __print(const string &x)
{
    cerr << '\"' << x << '\"';
}
void __print(bool x)
{
    cerr << (x ? "true" : "false");
}

template<typename T, typename V>
void __print(const pair<T, V> &x)
{
    cerr << '{';
    __print(x.first);
    cerr << ',';
    __print(x.second);
    cerr << '}';
}
template<typename T>
void __print(const T &x)
{
    int f = 0;
    cerr << '{';
    for (auto &i : x) cerr << (f++ ? "," : ""), __print(i);
    cerr << "}";
}
void _print()
{
    cerr << "]\n";
}
template <typename T, typename... V>
void _print(T t, V... v)
{
    __print(t);
    if (sizeof...(v)) cerr << ", ";
    _print(v...);
}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif
/*
░█▀▀▄ ░█▀▀▀ ░█▀▀█ ░█─░█ ░█▀▀█
░█─░█ ░█▀▀▀ ░█▀▀▄ ░█─░█ ░█─▄▄
░█▄▄▀ ░█▄▄▄ ░█▄▄█ ─▀▄▄▀ ░█▄▄█*/

ll testcases;

int main()
{
    TLE_na_ho;
    //READ THE QUESTION PROPERLY!!
    //testcases=1;
    cin >> testcases;
    while(testcases--)
    {
        ll n, m;
        cin >> n >> m;
        ll a[n][m];
        f(n)
        rep(j, 0, m)
        cin >> a[i][j];
        map<ll, ll> cnt;
        bool f[n][m] = {0};
        for(ll i = 0; i < n; i++)
        {
            for(ll j = 0; j < n; j++)
            {
                if( j > 0 && f[i][j] == 0 && f[i][j - 1] == 0 && a[i][j] == a[i][j - 1])
                {
                    cnt[a[i][j]]++;
                    f[i][j] = 1;
                    f[i][j - 1] = 1;

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

                }
                if( j < n - f[i][j] == 0 && f[i][j + 1] == 0 && 1 && a[i][j] == a[i][j + 1])
                {
                    cnt[a[i][j]]++;
                    f[i][j] = 1;
                    f[i][j + 1] = 1;

                }
                if( i < n - f[i][j] == 0 && f[i + 1][j] == 0 && 1 && a[i][j] == a[i + 1][j])
                {
                    cnt[a[i][j]]++;
                    f[i][j] = 1;
                    f[i + 1][j] = 1;
                }
            }
        }

        for(ll i = 0; i < n; i++)
        {
            for(ll j = 0; j < m; j++)
            {
                if(cnt[a[i][j]] > 0)
                {
                    cnt[a[i][j]]--;
                    a[i][j]++;
                }
            }
        }

        for(ll i = 0; i < n; i++)
        {
            for(ll j = 0; j < m; j++)
                cout << a[i][j] << ssp;
            cout << endl;
        }
    }

}


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

using   ll        = long long int;
using   pll       = pair<ll, ll>;
using   vll       = vector<ll>;
ll const max_size = 1024;
ll const mod      = 1e9 + 7;
ll const maxn     = 1e5 + 1;
#define endl        "\n"
#define ssp         " "
#define n_l         cout<<"\n"
#define TLE_na_ho   ios_base::sync_with_stdio(false);cin.tie(NULL)
#define pb          push_back
#define ff          first
#define ss          second
#define all(v)      v.begin(),v.end()
#define f(n)        for(ll i=0;i<n;i++)
#define rep(i,a,n)  for(ll i=a;i<n;i++)
#define repe(i,a,n) for(ll i=a;i<=n;i++)
#define repr(i,a,n) for(ll i=a;i>=n;i--)
#define ain(arr,n)  for(ll i1=0;i1<n;i1++ ) cin>>arr[i1]
#define aout(arr,n) for(ll i1=0;i1<n;i1++ ) cout<<arr[i1]<<ssp

/*
░█▀▀▄ ░█▀▀▀ ░█▀▀█ ░█─░█ ░█▀▀█
░█─░█ ░█▀▀▀ ░█▀▀▄ ░█─░█ ░█─▄▄
░█▄▄▀ ░█▄▄▄ ░█▄▄█ ─▀▄▄▀ ░█▄▄█*/
void __print(int x)
{
    cerr << x;
}
void __print(long x)
{
    cerr << x;
}
void __print(long long x)
{
    cerr << x;
}
void __print(unsigned x)
{
    cerr << x;
}
void __print(unsigned long x)
{
    cerr << x;
}
void __print(unsigned long long x)
{
    cerr << x;
}
void __print(float x)
{
    cerr << x;
}
void __print(double x)
{
    cerr << x;
}
void __print(long double x)
{
    cerr << x;
}
void __print(char x)
{
    cerr << '\'' << x << '\'';
}
void __print(const char *x)
{
    cerr << '\"' << x << '\"';
}
void __print(const string &x)
{
    cerr << '\"' << x << '\"';
}
void __print(bool x)
{
    cerr << (x ? "true" : "false");
}

template<typename T, typename V>
void __print(const pair<T, V> &x)
{
    cerr << '{';
    __print(x.first);
    cerr << ',';
    __print(x.second);
    cerr << '}';
}
template<typename T>
void __print(const T &x)
{
    int f = 0;
    cerr << '{';
    for (auto &i : x) cerr << (f++ ? "," : ""), __print(i);
    cerr << "}";
}
void _print()
{
    cerr << "]\n";
}
template <typename T, typename... V>
void _print(T t, V... v)
{
    __print(t);
    if (sizeof...(v)) cerr << ", ";
    _print(v...);
}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif
/*
░█▀▀▄ ░█▀▀▀ ░█▀▀█ ░█─░█ ░█▀▀█
░█─░█ ░█▀▀▀ ░█▀▀▄ ░█─░█ ░█─▄▄
░█▄▄▀ ░█▄▄▄ ░█▄▄█ ─▀▄▄▀ ░█▄▄█*/

ll testcases;

int main()
{
    TLE_na_ho;
    //READ THE QUESTION PROPERLY!!
    //testcases=1;
    cin >> testcases;
    while(testcases--)
    {
        ll n, m;
        cin >> n >> m;
        ll a[n][m];
        f(n)
        rep(j, 0, m)
        cin >> a[i][j];
        map<ll, ll> cnt;
        bool f[n][m] = {0};
        for(ll i = 0; i < n; i++)
        {
            for(ll j = 0; j < m; j++)
            {
                if( j > 0 && f[i][j] == 0 && a[i][j] == a[i][j - 1])
                {
                    cnt[a[i][j]]++;
                    f[i][j] = 1;
                    f[i][j - 1] = 1;

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

                }
                if( j < n - f[i][j] == 0 && 1 && a[i][j] == a[i][j + 1])
                {
                    cnt[a[i][j]]++;
                    f[i][j] = 1;
                    f[i][j + 1] = 1;

                }
                if( i < n - f[i][j] == 0 && 1 && a[i][j] == a[i + 1][j])
                {
                    cnt[a[i][j]]++;
                    f[i][j] = 1;
                    f[i + 1][j] = 1;
                }
            }
        }

        for(ll i = 0; i < n; i++)
        {
            for(ll j = 0; j < m; j++)
            {
                if(cnt[a[i][j]] > 0)
                {
                    cnt[a[i][j]]--;
                    a[i][j]++;
                }
            }
        }

        for(ll i = 0; i < n; i++)
        {
            for(ll j = 0; j < m; j++)
                cout << a[i][j] << ssp;
            cout << endl;
        }
    }

}


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

using   ll        = long long int;
using   pll       = pair<ll, ll>;
using   vll       = vector<ll>;
ll const max_size = 1024;
ll const mod      = 1e9 + 7;
ll const maxn     = 1e5 + 1;
#define endl        "\n"
#define ssp         " "
#define n_l         cout<<"\n"
#define TLE_na_ho   ios_base::sync_with_stdio(false);cin.tie(NULL)
#define pb          push_back
#define ff          first
#define ss          second
#define all(v)      v.begin(),v.end()
#define f(n)        for(ll i=0;i<n;i++)
#define rep(i,a,n)  for(ll i=a;i<n;i++)
#define repe(i,a,n) for(ll i=a;i<=n;i++)
#define repr(i,a,n) for(ll i=a;i>=n;i--)
#define ain(arr,n)  for(ll i1=0;i1<n;i1++ ) cin>>arr[i1]
#define aout(arr,n) for(ll i1=0;i1<n;i1++ ) cout<<arr[i1]<<ssp

/*
░█▀▀▄ ░█▀▀▀ ░█▀▀█ ░█─░█ ░█▀▀█
░█─░█ ░█▀▀▀ ░█▀▀▄ ░█─░█ ░█─▄▄
░█▄▄▀ ░█▄▄▄ ░█▄▄█ ─▀▄▄▀ ░█▄▄█*/
void __print(int x)
{
    cerr << x;
}
void __print(long x)
{
    cerr << x;
}
void __print(long long x)
{
    cerr << x;
}
void __print(unsigned x)
{
    cerr << x;
}
void __print(unsigned long x)
{
    cerr << x;
}
void __print(unsigned long long x)
{
    cerr << x;
}
void __print(float x)
{
    cerr << x;
}
void __print(double x)
{
    cerr << x;
}
void __print(long double x)
{
    cerr << x;
}
void __print(char x)
{
    cerr << '\'' << x << '\'';
}
void __print(const char *x)
{
    cerr << '\"' << x << '\"';
}
void __print(const string &x)
{
    cerr << '\"' << x << '\"';
}
void __print(bool x)
{
    cerr << (x ? "true" : "false");
}

template<typename T, typename V>
void __print(const pair<T, V> &x)
{
    cerr << '{';
    __print(x.first);
    cerr << ',';
    __print(x.second);
    cerr << '}';
}
template<typename T>
void __print(const T &x)
{
    int f = 0;
    cerr << '{';
    for (auto &i : x) cerr << (f++ ? "," : ""), __print(i);
    cerr << "}";
}
void _print()
{
    cerr << "]\n";
}
template <typename T, typename... V>
void _print(T t, V... v)
{
    __print(t);
    if (sizeof...(v)) cerr << ", ";
    _print(v...);
}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif
/*
░█▀▀▄ ░█▀▀▀ ░█▀▀█ ░█─░█ ░█▀▀█
░█─░█ ░█▀▀▀ ░█▀▀▄ ░█─░█ ░█─▄▄
░█▄▄▀ ░█▄▄▄ ░█▄▄█ ─▀▄▄▀ ░█▄▄█*/

ll testcases;

int main()
{
    TLE_na_ho;
    //READ THE QUESTION PROPERLY!!
    //testcases=1;
    cin >> testcases;
    while(testcases--)
    {
        ll n, m;
        cin >> n >> m;
        ll a[n][m];
        f(n)
        rep(j, 0, m)
        cin >> a[i][j];
        map<ll, ll> cnt;
        bool f[n][m] = {0};
        for(ll i = 0; i < n; i++)
        {
            for(ll j = 0; j < n; j++)
            {
                if( j > 0 && f[i][j] == 0 && f[i][j - 1] == 0 && a[i][j] == a[i][j - 1])
                {
                    cnt[a[i][j]]++;
                    f[i][j] = 1;
                    f[i][j - 1] = 1;

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

                }
                if( j < n - f[i][j] == 0 && f[i][j + 1] == 0 && 1 && a[i][j] == a[i][j + 1])
                {
                    cnt[a[i][j]]++;
                    f[i][j] = 1;
                    f[i][j + 1] = 1;

                }
                if( i < n - f[i][j] == 0 && f[i + 1][j] == 0 && 1 && a[i][j] == a[i + 1][j])
                {
                    cnt[a[i][j]]++;
                    f[i][j] = 1;
                    f[i + 1][j] = 1;
                }
            }
        }

        for(ll i = 0; i < n; i++)
        {
            for(ll j = 0; j < n; j++)
            {
                if(cnt[a[i][j]] > 0)
                {
                    cnt[a[i][j]]--;
                    a[i][j]++;
                }
            }
        }

        for(ll i = 0; i < n; i++)
        {
            for(ll j = 0; j < m; j++)
                cout << a[i][j] << ssp;
            cout << endl;
        }
    }

}


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

using   ll        = long long int;
using   pll       = pair<ll, ll>;
using   vll       = vector<ll>;
ll const max_size = 1024;
ll const mod      = 1e9 + 7;
ll const maxn     = 1e5 + 1;
#define endl        "\n"
#define ssp         " "
#define n_l         cout<<"\n"
#define TLE_na_ho   ios_base::sync_with_stdio(false);cin.tie(NULL)
#define pb          push_back
#define ff          first
#define ss          second
#define all(v)      v.begin(),v.end()
#define f(n)        for(ll i=0;i<n;i++)
#define rep(i,a,n)  for(ll i=a;i<n;i++)
#define repe(i,a,n) for(ll i=a;i<=n;i++)
#define repr(i,a,n) for(ll i=a;i>=n;i--)
#define ain(arr,n)  for(ll i1=0;i1<n;i1++ ) cin>>arr[i1]
#define aout(arr,n) for(ll i1=0;i1<n;i1++ ) cout<<arr[i1]<<ssp

/*
░█▀▀▄ ░█▀▀▀ ░█▀▀█ ░█─░█ ░█▀▀█
░█─░█ ░█▀▀▀ ░█▀▀▄ ░█─░█ ░█─▄▄
░█▄▄▀ ░█▄▄▄ ░█▄▄█ ─▀▄▄▀ ░█▄▄█*/
void __print(int x)
{
    cerr << x;
}
void __print(long x)
{
    cerr << x;
}
void __print(long long x)
{
    cerr << x;
}
void __print(unsigned x)
{
    cerr << x;
}
void __print(unsigned long x)
{
    cerr << x;
}
void __print(unsigned long long x)
{
    cerr << x;
}
void __print(float x)
{
    cerr << x;
}
void __print(double x)
{
    cerr << x;
}
void __print(long double x)
{
    cerr << x;
}
void __print(char x)
{
    cerr << '\'' << x << '\'';
}
void __print(const char *x)
{
    cerr << '\"' << x << '\"';
}
void __print(const string &x)
{
    cerr << '\"' << x << '\"';
}
void __print(bool x)
{
    cerr << (x ? "true" : "false");
}

template<typename T, typename V>
void __print(const pair<T, V> &x)
{
    cerr << '{';
    __print(x.first);
    cerr << ',';
    __print(x.second);
    cerr << '}';
}
template<typename T>
void __print(const T &x)
{
    int f = 0;
    cerr << '{';
    for (auto &i : x) cerr << (f++ ? "," : ""), __print(i);
    cerr << "}";
}
void _print()
{
    cerr << "]\n";
}
template <typename T, typename... V>
void _print(T t, V... v)
{
    __print(t);
    if (sizeof...(v)) cerr << ", ";
    _print(v...);
}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif
/*
░█▀▀▄ ░█▀▀▀ ░█▀▀█ ░█─░█ ░█▀▀█
░█─░█ ░█▀▀▀ ░█▀▀▄ ░█─░█ ░█─▄▄
░█▄▄▀ ░█▄▄▄ ░█▄▄█ ─▀▄▄▀ ░█▄▄█*/

ll testcases;

int main()
{
    TLE_na_ho;
    //READ THE QUESTION PROPERLY!!
    //testcases=1;
    cin >> testcases;
    while(testcases--)
    {
        ll n, m;
        cin >> n >> m;
        ll a[n][m];
        f(n)
        {
            rep(j, 0, m)
            {
                cin >> a[i][j];
                if((i + j) % 2 == a[i][j] % 2)
                    a[i][j]++;
            }
        }

        for(ll i = 0; i < n; i++)
        {
            for(ll j = 0; j < m; j++)
                cout << a[i][j] << ssp;
            cout << endl;
        }
    }
}


//Bismillahirrahmanirrahim

#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx")

#include <bits/stdc++.h>

using namespace std;

typedef long long lo;
typedef pair< lo,lo > PII;
typedef pair< lo,PII > PIII;

#define fi first
#define int long long
#define se second
#define mp make_pair
#define endl "\n"
#define pb push_back
#define fio() ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define FOR for(int i=1;i<=n;i++)
#define mid ((start+end)/2)
#define ort ((bas+son)/2)

const lo inf = 100000000000;
const lo KOK = 100000;
const lo LOG = 30;
const lo li = 105;
const lo mod = 1000000007;

int n,m,b[li],a[li][li],k,flag,t,use[li][li];
int cev;
string s;
vector<PIII> v;

int32_t main(void){
	scanf("%lld",&t);
	while(t--){
		scanf("%lld %lld",&n,&m);
		v.clear();
		FOR{
			for(int j=1;j<=m;j++){
				scanf("%lld",&a[i][j]);
				if(i%2==1){
					if(j%2==1 && a[i][j]%2==1)a[i][j]++;
					if(j%2==0 && a[i][j]%2==0)a[i][j]++;
				}
				else{
					if(j%2==1 && a[i][j]%2==0)a[i][j]++;
					if(j%2==0 && a[i][j]%2==1)a[i][j]++;
				}
			}
		}

		FOR{
			for(int j=1;j<=m;j++)printf("%lld ",a[i][j]);
			printf("\n");
		}
	}
	return 0;
}


//Bismillahirrahmanirrahim

#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx")

#include <bits/stdc++.h>

using namespace std;

typedef long long lo;
typedef pair< lo,lo > PII;
typedef pair< lo,PII > PIII;

#define fi first
#define int long long
#define se second
#define mp make_pair
#define endl "\n"
#define pb push_back
#define fio() ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define FOR for(int i=2;i<=n+1;i++)
#define mid ((start+end)/2)
#define ort ((bas+son)/2)

const lo inf = 100000000000;
const lo KOK = 100000;
const lo LOG = 30;
const lo li = 105;
const lo mod = 1000000007;

int n,m,b[li],k,flag,t,use[li][li];
int cev;
string s;
int a[li][li];
vector<PIII> v;

int32_t main(void){
	scanf("%lld",&t);
	while(t--){
		scanf("%lld %lld",&n,&m);
		v.clear();
		FOR{
			for(int j=2;j<=m+1;j++){
				scanf("%lld",&a[i][j]);
				v.pb({a[i][j],{i,j}});
			}
		}
		FOR{
			a[i][0]=-inf;
			a[i][1]=-inf;
			a[i][m+2]=-inf;
			a[i][m+3]=-inf;
		}
		for(int j=2;j<=m+1;j++){
			a[0][j]=-inf;
			a[1][j]=-inf;
			a[n+2][j]=-inf;
			a[n+3][j]=-inf;
		}
		sort(v.begin(),v.end());
		reverse(v.begin(),v.end());
		for(int i=0;i<(int)v.size();i++){
			int at=v[i].fi;
			int x=v[i].se.fi;
			int y=v[i].se.se;
			if(a[x][y]+1!=a[x-1][y] && a[x][y]+1!=a[x+1][y] && a[x][y]+1!=a[x][y+1] && a[x][y]+1!=a[x][y-1]){
				if(!(a[x][y]==a[x-1][y] && a[x][y]==a[x-2][y]) && !(a[x][y]==a[x-1][y] && a[x][y]==a[x-1][y-1]) && !(a[x][y]==a[x-1][y] && a[x][y]==a[x-1][y+1])){
					if(!(a[x][y]==a[x+1][y] && a[x][y]==a[x+2][y]) && !(a[x][y]==a[x+1][y] && a[x][y]==a[x+1][y-1]) && !(a[x][y]==a[x+1][y] && a[x][y]==a[x+1][y+1])){
						if(!(a[x][y]==a[x][y-1] && a[x][y]==a[x+1][y-1]) && !(a[x][y]==a[x][y-1] && a[x][y]==a[x-1][y-1]) && !(a[x][y]==a[x][y-1] && a[x][y]==a[x][y-2])){
							if(!(a[x][y]==a[x][y+1] && a[x][y]==a[x+1][y+1]) && !(a[x][y]==a[x][y+1] && a[x][y]==a[x-1][y+1]) && !(a[x][y]==a[x][y+1] && a[x][y]==a[x][y+2])){
								a[x][y]++;
							}
						}
					}
				}
			}
		}
		FOR{
			for(int j=2;j<=m+1;j++)printf("%lld ",a[i][j]);
			printf("\n");
		}
	}
	return 0;
}


//Bismillahirrahmanirrahim

#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx")

#include <bits/stdc++.h>

using namespace std;

typedef long long lo;
typedef pair< lo,lo > PII;
typedef pair< lo,PII > PIII;

#define fi first
#define int long long
#define se second
#define mp make_pair
#define endl "\n"
#define pb push_back
#define fio() ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define FOR for(int i=2;i<=n+1;i++)
#define mid ((start+end)/2)
#define ort ((bas+son)/2)

const lo inf = 100000000000;
const lo KOK = 100000;
const lo LOG = 30;
const lo li = 105;
const lo mod = 1000000007;

int n,m,b[li],k,flag,t,use[li][li];
int cev;
string s;
int a[li][li];
vector<PIII> v;

int32_t main(void){
	scanf("%lld",&t);
	while(t--){
		scanf("%lld %lld",&n,&m);
		v.clear();
		FOR{
			for(int j=2;j<=m+1;j++){
				scanf("%lld",&a[i][j]);
				v.pb({a[i][j],{i,j}});
			}
		}
		FOR{
			a[i][0]=-inf;
			a[i][1]=-inf;
			a[i][m+2]=-inf;
			a[i][m+3]=-inf;
		}
		for(int j=2;j<=m+1;j++){
			a[0][j]=-inf;
			a[1][j]=-inf;
			a[n+2][j]=-inf;
			a[n+3][j]=-inf;
		}
		sort(v.begin(),v.end());
		reverse(v.begin(),v.end());
		for(int i=0;i<(int)v.size();i++){
			int at=v[i].fi;
			int x=v[i].se.fi;
			int y=v[i].se.se;
			if(a[x][y]+1!=a[x-1][y] && a[x][y]+1!=a[x+1][y] && a[x][y]+1!=a[x][y+1] && a[x][y]+1!=a[x][y-1]){
				if(!(a[x][y]==a[x-1][y] && a[x][y]==a[x-2][y]) && !(a[x][y]==a[x-1][y] && a[x][y]==a[x-1][y-1]) && !(a[x][y]==a[x-1][y] && a[x][y]==a[x-1][y+1])){
					//~ if(!(a[x][y]==a[x+1][y] && a[x][y]==a[x+2][y]) && !(a[x][y]==a[x+1][y] && a[x][y]==a[x+1][y-1]) && !(a[x][y]==a[x+1][y] && a[x][y]==a[x+1][y+1])){
						if(!(a[x][y]==a[x][y-1] && a[x][y]==a[x+1][y-1]) && !(a[x][y]==a[x][y-1] && a[x][y]==a[x-1][y-1]) && !(a[x][y]==a[x][y-1] && a[x][y]==a[x][y-2])){
							//~ if(!(a[x][y]==a[x][y+1] && a[x][y]==a[x+1][y+1]) && !(a[x][y]==a[x][y+1] && a[x][y]==a[x-1][y+1]) && !(a[x][y]==a[x][y+1] && a[x][y]==a[x][y+2])){
								a[x][y]++;
							}
						//~ }
					//~ }
				}
			}
		}
		FOR{
			for(int j=2;j<=m+1;j++)printf("%lld ",a[i][j]);
			printf("\n");
		}
	}
	return 0;
}


//Bismillahirrahmanirrahim

#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx")

#include <bits/stdc++.h>

using namespace std;

typedef long long lo;
typedef pair< lo,lo > PII;

#define fi first
#define int long long
#define se second
#define mp make_pair
#define endl "\n"
#define pb push_back
#define fio() ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define FOR for(int i=1;i<=n;i++)
#define mid ((start+end)/2)
#define ort ((bas+son)/2)

const lo inf = 100000000000;
const lo KOK = 100000;
const lo LOG = 30;
const lo li = 105;
const lo mod = 1000000007;

int n,m,b[li],a[li][li],k,flag,t,use[li][li];
int cev;
string s;
vector<int> v;

int32_t main(void){
	scanf("%lld",&t);
	while(t--){
		scanf("%lld %lld",&n,&m);
		FOR{
			for(int j=1;j<=m;j++)scanf("%lld",&a[i][j]);
		}
		FOR{
			for(int j=1;j<=m;j++)use[i][j]=0;
		}
		FOR{
			a[i][0]=-inf;
			a[i][m+1]=-inf;
		}
		for(int j=1;j<=m;j++){
			a[0][j]=-inf;
			a[n+1][j]=-inf;
		}
		FOR{
			for(int j=1;j<=m;j++){

				if((j!=1 && a[i][j]==a[i][j-1])){
					if(a[i][j-1]+1!=a[i-1][j-1] && a[i][j-1]+1!=a[i+1][j-1] && a[i][j-1]+1!=a[i][j-2] && use[i][j-1]==0){a[i][j-1]++;use[i][j-1]=1;}
					else{a[i][j]++;use[i][j]=1;}
				}
			}
		}
		FOR{
			for(int j=1;j<=m;j++){
				if((i!=1 && a[i][j]==a[i-1][j])){
					if(a[i-1][j]+1!=a[i-1][j-1] && a[i-1][j]+1!=a[i-1][j+1] && a[i-1][j]+1!=a[i-2][j] && use[i-1][j]==0){a[i-1][j]++;use[i-1][j]=1;}
					else{a[i][j]++;use[i][j]=1;}
				}
				//~ if((j!=1 && a[i][j]==a[i][j-1])){
					//~ if(a[i][j-1]+1!=a[i-1][j-1] && a[i][j-1]+1!=a[i+1][j-1] && a[i][j-1]+1!=a[i][j-2] && use[i][j-1]==0){a[i][j-1]++;use[i][j-1]=1;}
					//~ else{a[i][j]++;use[i][j]=1;}
				//~ }
			}
		}

		FOR{
			for(int j=1;j<=m;j++)printf("%lld ",a[i][j]);
			printf("\n");
		}
	}
	return 0;
}


//Bismillahirrahmanirrahim

#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx")

#include <bits/stdc++.h>

using namespace std;

typedef long long lo;
typedef pair< lo,lo > PII;
typedef pair< lo,PII > PIII;

#define fi first
#define int long long
#define se second
#define mp make_pair
#define endl "\n"
#define pb push_back
#define fio() ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define FOR for(int i=1;i<=n;i++)
#define mid ((start+end)/2)
#define ort ((bas+son)/2)

const lo inf = 100000000000;
const lo KOK = 100000;
const lo LOG = 30;
const lo li = 105;
const lo mod = 1000000007;

int n,m,b[li],a[li][li],k,flag,t,use[li][li];
int cev;
string s;
vector<PIII> v;

int32_t main(void){
	scanf("%lld",&t);
	while(t--){
		scanf("%lld %lld",&n,&m);
		v.clear();
		FOR{
			for(int j=1;j<=m;j++){
				scanf("%lld",&a[i][j]);
				v.pb({a[i][j],{i,j}});
			}
		}
		FOR{
			a[i][0]=-inf;
			a[i][m+1]=-inf;
		}
		for(int j=1;j<=m;j++){
			a[0][j]=-inf;
			a[n+1][j]=-inf;
		}
		sort(v.begin(),v.end());
		reverse(v.begin(),v.end());
		for(int i=0;i<(int)v.size();i++){
			int at=v[i].fi;
			int x=v[i].se.fi;
			int y=v[i].se.se;
			if(a[x][y]+1!=a[x-1][y] && a[x][y]+1!=a[x+1][y] && a[x][y]+1!=a[x][y+1] && a[x][y]+1!=a[x][y-1])a[x][y]++;
		}
		FOR{
			for(int j=1;j<=m;j++)printf("%lld ",a[i][j]);
			printf("\n");
		}
	}
	return 0;
}


//Bismillahirrahmanirrahim

#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx")

#include <bits/stdc++.h>

using namespace std;

typedef long long lo;
typedef pair< lo,lo > PII;
typedef pair< lo,PII > PIII;

#define fi first
#define int long long
#define se second
#define mp make_pair
#define endl "\n"
#define pb push_back
#define fio() ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define FOR for(int i=1;i<=n;i++)
#define mid ((start+end)/2)
#define ort ((bas+son)/2)

const lo inf = 100000000000;
const lo KOK = 100000;
const lo LOG = 30;
const lo li = 105;
const lo mod = 1000000007;

int n,m,b[li],a[li][li],k,flag,t,use[li][li];
int cev;
string s;
vector<PIII> v;

int32_t main(void){
	scanf("%lld",&t);
	while(t--){
		scanf("%lld %lld",&n,&m);
		v.clear();
		FOR{
			for(int j=1;j<=m;j++){
				scanf("%lld",&a[i][j]);
				v.pb({a[i][j],{i,j}});
			}
		}
		FOR{
			a[i][0]=-inf;
			a[i][m+1]=-inf;
		}
		for(int j=1;j<=m;j++){
			a[0][j]=-inf;
			a[n+1][j]=-inf;
		}
		sort(v.begin(),v.end());
		//~ reverse(v.begin(),v.end());
		for(int i=0;i<(int)v.size();i++){
			int at=v[i].fi;
			int x=v[i].se.fi;
			int y=v[i].se.se;
			if(a[x][y]==a[x-1][y] || a[x][y]==a[x+1][y] || a[x][y]==a[x][y+1] || a[x][y]==a[x][y-1])a[x][y]++;
		}
		FOR{
			for(int j=1;j<=m;j++)printf("%lld ",a[i][j]);
			printf("\n");
		}
	}
	return 0;
}


//Bismillahirrahmanirrahim

#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx")

#include <bits/stdc++.h>

using namespace std;

typedef long long lo;
typedef pair< lo,lo > PII;
typedef pair< lo,PII > PIII;

#define fi first
#define int long long
#define se second
#define mp make_pair
#define endl "\n"
#define pb push_back
#define fio() ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define FOR for(int i=1;i<=n;i++)
#define mid ((start+end)/2)
#define ort ((bas+son)/2)

const lo inf = 100000000000;
const lo KOK = 100000;
const lo LOG = 30;
const lo li = 105;
const lo mod = 1000000007;

int n,m,b[li],a[li][li],k,flag,t,use[li][li];
int cev;
string s;
vector<PIII> v;

int32_t main(void){
	scanf("%lld",&t);
	while(t--){
		scanf("%lld %lld",&n,&m);
		v.clear();
		FOR{
			for(int j=1;j<=m;j++){
				scanf("%lld",&a[i][j]);
				v.pb({a[i][j],{i,j}});
			}
		}
		FOR{
			a[i][0]=-inf;
			a[i][m+1]=-inf;
		}
		for(int j=1;j<=m;j++){
			a[0][j]=-inf;
			a[n+1][j]=-inf;
		}
		sort(v.begin(),v.end());
		reverse(v.begin(),v.end());
		for(int i=0;i<(int)v.size();i++){
			int at=v[i].fi;
			int x=v[i].se.fi;
			int y=v[i].se.se;
			if(a[x][y]==a[x-1][y] || a[x][y]==a[x+1][y] || a[x][y]==a[x][y+1] || a[x][y]==a[x][y-1])a[x][y]++;
		}
		FOR{
			for(int j=1;j<=m;j++)printf("%lld ",a[i][j]);
			printf("\n");
		}
	}
	return 0;
}


//Bismillahirrahmanirrahim

#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx")

#include <bits/stdc++.h>

using namespace std;

typedef long long lo;
typedef pair< lo,lo > PII;

#define fi first
#define int long long
#define se second
#define mp make_pair
#define endl "\n"
#define pb push_back
#define fio() ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define FOR for(int i=1;i<=n;i++)
#define mid ((start+end)/2)
#define ort ((bas+son)/2)

const lo inf = 100000000000;
const lo KOK = 100000;
const lo LOG = 30;
const lo li = 105;
const lo mod = 1000000007;

int n,m,b[li],a[li][li],k,flag,t,use[li][li];
int cev;
string s;
vector<int> v;

int32_t main(void){
	scanf("%lld",&t);
	while(t--){
		scanf("%lld %lld",&n,&m);
		FOR{
			for(int j=1;j<=m;j++)scanf("%lld",&a[i][j]);
		}
		FOR{
			for(int j=1;j<=m;j++)use[i][j]=0;
		}
		FOR{
			a[i][0]=-inf;
			a[i][m+1]=-inf;
		}
		for(int j=1;j<=m;j++){
			a[0][j]=-inf;
			a[n+1][j]=-inf;
		}
		FOR{
			for(int j=1;j<=m;j++){
				if((i!=1 && a[i][j]==a[i-1][j])){
					if(a[i-1][j]+1!=a[i-1][j-1] && a[i-1][j]+1!=a[i-1][j+1] && a[i-1][j]+1!=a[i-2][j] && use[i-1][j]==0){a[i-1][j]++;use[i-1][j]=1;}
					else{a[i][j]++;use[i][j]=1;}
				}
				if((j!=1 && a[i][j]==a[i][j-1])){
					if(a[i][j-1]+1!=a[i-1][j-1] && a[i][j-1]+1!=a[i+1][j-1] && a[i][j-1]+1!=a[i][j-2] && use[i][j-1]==0){a[i][j-1]++;use[i][j-1]=1;}
					else{a[i][j]++;use[i][j]=1;}
				}
			}
		}
		FOR{
			for(int j=1;j<=m;j++)printf("%lld ",a[i][j]);
			printf("\n");
		}
	}
	return 0;
}


//Bismillahirrahmanirrahim

#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx")

#include <bits/stdc++.h>

using namespace std;

typedef long long lo;
typedef pair< lo,lo > PII;

#define fi first
#define int long long
#define se second
#define mp make_pair
#define endl "\n"
#define pb push_back
#define fio() ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define FOR for(int i=1;i<=n;i++)
#define mid ((start+end)/2)
#define ort ((bas+son)/2)

const lo inf = 100000000000;
const lo KOK = 100000;
const lo LOG = 30;
const lo li = 105;
const lo mod = 1000000007;

int n,m,b[li],a[li][li],k,flag,t,use[li][li];
int cev;
string s;
vector<int> v;

int32_t main(void){
	scanf("%lld",&t);
	while(t--){
		scanf("%lld %lld",&n,&m);
		FOR{
			for(int j=1;j<=m;j++)scanf("%lld",&a[i][j]);
		}
		FOR{
			for(int j=1;j<=m;j++)use[i][j]=0;
		}
		FOR{
			a[i][0]=-inf;
			a[i][m+1]=-inf;
		}
		for(int j=1;j<=m;j++){
			a[0][j]=-inf;
			a[n+1][j]=-inf;
		}
		FOR{
			for(int j=1;j<=m;j++){
				if((i!=1 && a[i][j]==a[i-1][j])){
					if(a[i-1][j]+1!=a[i-1][j-1] && a[i-1][j]+1!=a[i-1][j+1] && a[i-1][j]+1!=a[i-2][j] && use[i-1][j]==0){a[i-1][j]++;use[i-1][j]=1;}
					else{a[i][j]++;use[i][j]=1;}
				}
				//~ if((j!=1 && a[i][j]==a[i][j-1])){
					//~ if(a[i][j-1]+1!=a[i-1][j-1] && a[i][j-1]+1!=a[i+1][j-1] && a[i][j-1]+1!=a[i][j-2] && use[i][j-1]==0){a[i][j-1]++;use[i][j-1]=1;}
					//~ else{a[i][j]++;use[i][j]=1;}
				//~ }
			}
		}
		FOR{
			for(int j=1;j<=m;j++){

				if((j!=1 && a[i][j]==a[i][j-1])){
					if(a[i][j-1]+1!=a[i-1][j-1] && a[i][j-1]+1!=a[i+1][j-1] && a[i][j-1]+1!=a[i][j-2] && use[i][j-1]==0){a[i][j-1]++;use[i][j-1]=1;}
					else{a[i][j]++;use[i][j]=1;}
				}
			}
		}
		FOR{
			for(int j=1;j<=m;j++)printf("%lld ",a[i][j]);
			printf("\n");
		}
	}
	return 0;
}


#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];
            }
        }
        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(abs(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>
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(abs(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>
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];
            }
        }
        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(abs(j-i)==1 and flag==0 and abs(a[i][j]-a[j][i])==1){
                    a[i][j]+=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;
                }
                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;
                }
            }
        }
//        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[101][101];
        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(abs(j-i)==1 and flag==0 and abs(a[i][j]-a[j][i])==1){
                    a[i][j]+=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;
                }
                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;
                }
            }
        }
//        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[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[1][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[1][j]%2==1){
                        a[1][j]+=1;
                    }
                }else{
                    if(a[1][j]%2==0){
                        a[1][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==1){
                            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[101][101];
        for(i=1;i<=n;i++){
            for(j=1;j<=m;j++){
                cin>>a[i][j];
            }
        }
        flag=0;
        for(i=1;i<=n;i++){
            if(i%2==1){
                for(j=1;j<=m;j++){
                    if(a[i][j]%2==0){
                        a[i][j]+=1;
                    }
                }
            }else{
                for(j=1;j<=m;j++){
                    if(a[i][j]%2==1){
                        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[101][101];
        for(i=1;i<=n;i++){
            for(j=1;j<=m;j++){
                cin>>a[i][j];
            }
        }
        flag=0;
        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[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[1][j]%2==1){
                        a[1][j]+=1;
                    }
                }else{
                    if(a[1][j]%2==0){
                        a[1][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==1){
                            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[101][101];
        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;
                        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>=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[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==1){
                            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;
        }
    }

}