t = int(input()) for _ in range(t): h, w = map(int, input().split()) ans = [[0] * w for _ in range(h)] for i in range(h): for j in range(w): if h % 3 == 1: ht = (i % 3 == 0) else: ht = (i % 3 == 2) if w % 3 == 1: wt = (j % 3 == 0) else: wt = (j % 3 == 2) if ht and wt: ans[i][j] = 0 elif ht or wt: ans[i][j] = 1 else: ans[i][j] = 2 for row in ans: print(*row)