Help me in solving SESO05 problem

My issue

Question not understanded properly!

My code

# cook your dish here

for _ in range(int(input())):
    
    

Learning course: Data structures and Algorithms
Problem Link: https://www.codechef.com/learn/course/pvp-dsa/PVPDAA13/problems/SESO05