MIUTGA - Make IUT Great Again

no tags 

Few years back IUT (International University Of Technology) authority decided to increase the number of students. As more students are getting admitted every year but the number of classroom didn't increase, the classrooms became overpopulated. As people are complaining about this, and making new classrooms is not possible in next few years one of the very intelligent person of the authority gave an idea to tackle this situation. It is that, they will not increase the classrooms rather they will distribute the classes into rooms such a way that it doesn't look like overpopulated although all the students come out of the class at the same time. So, It'll create an illusion amongst the visitor and they will think IUT is great as before.

The distribution process is that for every class this class will either contain more students than all the adjacent classes or contain less students than the adjacent classes. All the classes are situated in a line, so each class has two adjacent classroom except the 1st and the last classroom.

Suppose there are n classroom and the number of students of that classrooms are a1, a2, a3, a4 ... aN

You'll have to distribute the classes as

  • a1 > a2 < a3 > a4 < ... aN, or
  • a1 < a2 > a3 < a4 > ... aN

However you can only do one type of operation. You can swap the classrooms at position i and n-i+1.

You'll have to determine the minimum number of operations to distribute the classrooms and make IUT great again. If it's impossible print -1.

Input

First line of the input contains t, number of testcases. Then each testcase takes a integer n, number of rooms and then n integers the population of n'th class.

1 < t < 10

0 < n < 105

0 < ai < 109

Output

For each testcase on separate line print the minimum number of operations or -1 if not possible.

Example

Input:
2
6
1 2 3 4 5 6
5
5 2 4 3 5

Output:
1
0

hide comments
Jacob Plachta: 2018-11-22 05:13:08

The classroom positions (e.g. i and n-i+1) are 0-indexed (0..(n-1)).
:::reply: No, 1 indexed. 1,2,3.....n.. Read the statement carefully.

Last edit: 2018-11-30 17:38:54

Added by:Safayet
Date:2018-11-17
Time limit:1s-3s
Source limit:50000B
Memory limit:1536MB
Cluster: Cube (Intel G860)
Languages:All