#UnknownID25. XHXMMMl31UFZWg#-@_/

XHXMMMl31UFZWg#-@_/

Statement

Monocarp wants to throw a party. He has n n friends, and he wants to have at least 2 2 of them at his party.

The i i -th friend's best friend is pi p_i . All pi p_i are distinct, and for every i[1,n] i \in [1, n] , pii p_i \ne i .

Monocarp can send invitations to friends. The i i -th friend comes to the party if both the i i -th friend and the pi p_i -th friend receive an invitation (note that the pi p_i -th friend doesn't have to actually come to the party). Each invitation is sent to exactly one of the friends.

For example, if p=[3,1,2,5,4] p = [3, 1, 2, 5, 4] , and Monocarp sends invitations to the friends [1,2,4,5] [1, 2, 4, 5] , then the friends [2,4,5] [2, 4, 5] will come to the party. The friend 1 1 won't come since his best friend didn't receive an invitation; the friend 3 3 won't come since he didn't receive an invitation.

Calculate the minimum number of invitations Monocarp has to send so that at least 2 2 friends come to the party.

Format

Input

The first line contains one integer t t ( 1t5000 1 \le t \le 5000 ) — the number of test cases.

Each test case consists of two lines:

  • the first line contains one integer n n ( 2n50 2 \le n \le 50 ) — the number of friends;
  • the second line contains n n integers p1,p2,,pn p_1, p_2, \dots, p_n ( 1pin 1 \le p_i \le n ; pii p_i \ne i ; all pi p_i are distinct).

Output

Print one integer — the minimum number of invitations Monocarp has to send.

Sample

3
5
3 1 2 5 4
4
2 3 4 1
2
2 1
2
3
2