import sys readline=sys.stdin.readline T=int(readline()) lst=[[0,1,1],[1,2,2],[1,2,2]] for t in range(T): H,W=map(int,readline().split()) if H%3==0: Hl,Hr=0,H elif H%3==1: Hl,Hr=0,H elif H%3==2: Hl,Hr=-2,H-2 if W%3==0: Wl,Wr=0,W elif W%3==1: Wl,Wr=0,W elif W%3==2: Wl,Wr=-2,W-2 ans_lst=[[lst[h%3][w%3] for w in range(Wl,Wr)] for h in range(Hl,Hr)] for h in range(H): print(*ans_lst[h])