T = int(input()) for _ in range(T): N, L = map(int, input().split()) x, y = [list(map((-1).__add__, i)) for i in zip(*[list(map(int, input().split())) for _ in range(N)])] print(len(x)) for i in range(len(x)): print(x[i], y[i])