1372_C. Omkar and Baseball
Patrick likes to play baseball, but sometimes he will spend so many hours hitting home runs that his mind starts to get foggy! Patrick is sure that his scores across n sessions follow the identity permutation (ie. in the first game he scores 1 point, in the second game he scores 2 points and so on). However, when he checks back to his record, he sees that all the numbers are mixed up! 

Define a special exchange as the following: choose any subarray of the scores and permute elements such that no element of subarray gets to the same position as it was before the exchange. For example, performing a special exchange on [1,2,3] can yield [3,1,2] but it cannot yield [3,2,1] since the 2 is in the same position. 

Given a permutation of n integers, please help Patrick find the minimum number of special exchanges needed to make the permutation sorted! It can be proved that under given constraints this number doesn't exceed 10^{18}.

An array a is a subarray of an array b if a can be obtained from b by deletion of several (possibly, zero or all) elements from the beginning and several (possibly, zero or all) elements from the end.

Input

Each test contains multiple test cases. The first line contains the number of test cases t (1 ≤ t ≤ 100). Description of the test cases follows.

The first line of each test case contains integer n (1 ≤ n ≤ 2 ⋅ 10^5) — the length of the given permutation.

The second line of each test case contains n integers a_{1},a_{2},...,a_{n} (1 ≤ a_{i} ≤ n) — the initial permutation.

It is guaranteed that the sum of n over all test cases does not exceed 2 ⋅ 10^5.

Output

For each test case, output one integer: the minimum number of special exchanges needed to sort the permutation.

Example

Input


2
5
1 2 3 4 5
7
3 2 4 5 1 6 7


Output


0
2

Note

In the first permutation, it is already sorted so no exchanges are needed.

It can be shown that you need at least 2 exchanges to sort the second permutation.

[3, 2, 4, 5, 1, 6, 7]

Perform special exchange on range (1, 5)

[4, 1, 2, 3, 5, 6, 7]

Perform special exchange on range (1, 4)

[1, 2, 3, 4, 5, 6, 7]
```python
import sys
import math
import heapq
import collections
def inputnum():
    return(int(input()))
def inputnums():
    return(map(int,input().split()))
def inputlist():
    return(list(map(int,input().split())))
def inputstring():
    return([x for x in input()])
def inputmatrixchar(rows):
    arr2d = [[j for j in input().strip()] for i in range(rows)] 
    return arr2d
def inputmatrixint(rows):
    arr2d = []
    for _ in range(rows):
        arr2d.append([int(i) for i in input().split()])
    return arr2d
    
t=int(input())
for q in range(t):
    n = inputnum()
    a = inputlist()
    wrong = 0
    firstwrong = False
    secondwrong = False
    for i in range(n):
        if i+1 != a[i]:
            if not firstwrong:
                firstwrong = True
            elif firstwrong and a[i-1] == i and i > 1:
                secondwrong = True
            wrong += 1 
        
    if wrong == 0:
        print(0)
    elif not secondwrong:
        print(1)
    else:
        print(2)
```