#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define all(x) (x).begin(),(x).end()
template<class T>bool chmin(T&a, const T&b){if(a>b){a=b;return 1;}return 0;}
template<class T>bool chmax(T&a, const T&b){if(a<b){a=b;return 1;}return 0;}

int main(){
    int t;
    cin >> t;
    rep(houren,t){
        int h,w,x=2,y=2;
        cin >> h >> w;
        if(h%3==1) x=0;
        if(w%3==1) y=0;
        rep(i,h){
            rep(j,w){
                if(i%3==x && j%3==y) cout << 0 << " ";
                else if(i%3==x || j%3==y) cout << 1 << " ";
                else cout << 2 << " ";
            }
            cout << '\n';
        }
    }
    return 0;
}