import sys

is_first_input = False

for line in sys.stdin:
	if not is_first_input:	
		start_input = int(line.rstrip())
		#print ("start_input = ", start_input)
		is_first_input = True
	else:
		everything_ok = False
		if start_input == 1: 
			everything_ok = True

		numbers = list(map(int, line.rstrip().split(' ')))
		#print("NEW TEST")
		number_of_iterations = 0
		
		first_index = 0
		finish = False
		not_increment = False
		while not everything_ok:
			for index, number in enumerate(numbers):
				if number != index + 1:
					everything_ok = False
					break
				if index + 1 == len(numbers):
					#print("OK")
					everything_ok = True
					finish = True


			if finish:
				finish = False
				break

			if numbers[first_index] == first_index + 1:
				first_index += 1
			#print(numbers)
			
			#print("number_of_iterations = ", number_of_iterations)
			#print("before = numbers[0] = ", numbers[first_index], ", numbers[first - 1] = ", numbers[numbers[first_index] - 1])
			first = numbers[first_index]
			firsts_place = numbers[first - 1]
			temp = numbers[first_index]
			numbers[first_index] = numbers[first - 1]
			numbers[first - 1] = temp
			#print("AFTER = numbers[0] = ", numbers[first_index], ", numbers[first - 1] = ", numbers[first - 1])
			
					
			number_of_iterations += 1
			
			
		
		print(number_of_iterations)
		is_first_input = False
