A = [] for i in range(35): A.append([0, 1, 1]*100) A.append([1, 2, 2]*100) A.append([1, 2, 2]*100) t = int(input()) for _ in range(t): h, w = map(int, input().split()) if h%3 == 2: hoff = 1 else: hoff = 0 if w%3 == 2: woff = 1 else: woff = 0 for i in range(hoff, h+hoff): print(*A[i][woff:w+woff])