Help me in solving GCD_1 problem

My issue

1 2 3
4 5 6
is this way not possible?
for i in range(int(input())):
n, m = map(int, input().split())
a = [[0] * m for j in range(n)]
c = 2
for l in range(n):
for k in range(m):
a[l][k] = c
c += 1
for x in range(n):
for y in range(m):
print(a[y], end=" ")
print()
why test case is failing

My code

# cook your dish here
for i in range(int(input())):
    n, m = map(int, input().split())
    a = [[0] * m for j in range(n)]
    c = 2
    for l in range(n):
        for k in range(m):
            a[l][k] = c
            c += 1
    for x in range(n):
        for y in range(m):
            print(a[x][y], end=" ")
        print()

Problem Link: GCD to 1 (Easy) Practice Coding Problem

def construct_matrix(N, M):
matrix =
for i in range(1, N + 1):
row = [(i + j + N) for j in range(1, M + 1)]
matrix.append(row)
return matrix

def solve():
T = int(input())
for _ in range(T):
N, M = map(int, input().split())
result_matrix = construct_matrix(N, M)
for row in result_matrix:
print(" ".join(map(str, row)))

solve()

This is the easiest way . Use functions for easy solving…!
hope you got it.