num = input()
for i in range(0,num):
	str_input = raw_input()
	first_input_list = str_input.split()
	temp_str = ""
	for j in range(0,int(first_input_list[1])):
		string = raw_input()
		temp_str = temp_str + " " + string 
	print int(first_input_list[0])-1