import sys #input = sys.stdin.readline #input = sys.stdin.buffer.readline #文字列はダメ #sys.setrecursionlimit(1000000) #import bisect #import itertools #import random #from heapq import heapify, heappop, heappush #from collections import defaultdict #from collections import deque #import copy #import math #from functools import lru_cache #@lru_cache(maxsize=None) #MOD = pow(10,9) + 7 #MOD = 998244353 #dx = [1,0,-1,0] #dy = [0,1,0,-1] A = [] MAX = 10 for i in range(MAX): temp = [] for j in range(MAX): if i%3 == j%3 == 0: v = 0 elif i%3 == 0 or j %3 == 0: v = 1 else: v = 2 temp.append(v) A.append(temp) #print(A) def main(): T = int(input()) for _ in range(T): H,W = map(int,input().split()) for i in range(H): print(*A[i][:W]) if __name__ == '__main__': main()