for _ in range(int(input())): H,W=map(int,input().split()) if H==1 and W==1: print(0) elif H==2 and W==2: print("2 2\n2 2") elif H==3 and W==3: print("2 2 2\n2 0 2\n2 2 2") else: print(-1)