Help me in solving LB08A problem what to next

My issue

My code

# Step 1: Read and understand the problem statement and sample test cases



# Click on Next once you are ready to proceed.

T=int(input())
for i in range(T):
    N,M=map(int,input().split())
    

Learning course: Python for problem solving - 2
Problem Link: CodeChef: Practical coding for everyone