#include <algorithm>
#include <iomanip>
#include <iostream>
#include <vector>
#include <set>
#include <numeric>
#include <map>
#include <unordered_map>
using namespace std;
#define all(a) a.begin(), a.end()
#define ll long long
#define fo(i,n) for (long long i = 0; i < n; i++)
bool comp(pair<char,ll> a, pair<char,ll> b)
{
    return (a.first < b.first);
}
bool comp2(pair<char,ll> a, pair<char,ll> b)
{
    return (a.first > b.first);
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);
    ll n,m,i;
    ll a,b;
    string input;
    cin >> i;
    while (i--)
    {
        cin >> n >> m;
        vector<vector<ll>> nums(n,vector<ll>(m,0));
        fo(j,n)
        {
            fo(k,m)
            {
                cin >> a;
                nums[j][k] = a;
            }
        }
        for (auto z : nums)
        {
            for (auto s : z)
            {
                cout << s << ' ';
            }
        }
    }
}