for _ in range(int(input())): n, m = map(int, input().split()) if n == 1 and m == 1: print("0\n1 1") continue if n % 2 == 1 or m % 2 == 1: print(-1) continue print(n*m - 1) for i in range(0, n, 2): t = range(0, m, 2) for j in (t if i % 4 == 0 else reversed(t)): if i % 4 == 0: if j == 0: print(i+1, j+2) print(i+2, j+1) else: print(i+2, j+1) print(i+1, j+2) print(i+1, j+1) print(i+2, j+2) else: print(i+1, j+2) print(i+2, j+1) if j == 0: print(i+1, j+1) print(i+2, j+2) else: print(i+2, j+2) print(i+1, j+1)