Help me in solving TREEREQ1 problem

My issue

the second space contain n space integers

tree requirements

My code

# cook your dish here
T=int(input())
N,M=map(int,input().split(' '))

Problem Link: Tree Requirements (Easy) Practice Coding Problem