def main():
    tc=int(raw_input())
    while(tc):
        n,m=map(int,raw_input().split(" "))
        while(m):
            c1,c2=map(int,raw_input().split(" "))
            m-=1
        print n-1
        tc-=1
main()