Polycarp is playing a new computer game. This game has n stones in a row. The stone on the position i has integer power a_i. The powers of all stones are distinct.

Each turn Polycarp can destroy either stone on the first position or stone on the last position (in other words, either the leftmost or the rightmost stone). When Polycarp destroys the stone it does not exist any more.

Now, Polycarp wants two achievements. He gets them if he destroys the stone with the least power and the stone with the greatest power. Help Polycarp find out what is the minimum number of moves he should make in order to achieve his goal.

For example, if n = 5 and a = [1, 5, 4, 3, 2], then Polycarp could make the following moves: 

  * Destroy the leftmost stone. After this move a = [5, 4, 3, 2]; 
  * Destroy the rightmost stone. After this move a = [5, 4, 3]; 
  * Destroy the leftmost stone. After this move a = [4, 3]. Polycarp destroyed the stones with the greatest and least power, so he can end the game. 



Please note that in the example above, you can complete the game in two steps. For example: 

  * Destroy the leftmost stone. After this move a = [5, 4, 3, 2]; 
  * Destroy the leftmost stone. After this move a = [4, 3, 2]. Polycarp destroyed the stones with the greatest and least power, so he can end the game. 

Input

The first line contains an integer t (1 ≤ t ≤ 100). Then t test cases follow.

The first line of each test case contains one integer n (2 ≤ n ≤ 100) — the number of stones.

The second line contains n distinct integers a_1, a_2, …, a_n (1 ≤ a_i ≤ n) — the power of the stones.

Output

For each test case, output the minimum number of moves required to destroy the stones with the greatest and the lowest power.

Example

Input


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


Output


2
4
5
3
2
    import java.io.*;
    import java.util.*;
    import java.lang.Math;


    public class Main {

          static PrintWriter pw;
          static Scanner sc;
          static StringBuilder ans;
          static long mod = 1000000000+7;

          static void pn(final Object arg) {
               pw.print(arg);          
               pw.flush();      
          }     

          /*-------------- for input in an value ---------------------*/
          static int ni()     { return sc.nextInt();       }
          static long nl()    { return sc.nextLong();      }
          static double nd()  { return sc.nextDouble();    }
          static String ns()  { return sc.next();          }


          static void ap(int arg)           { ans.append(arg); }
          static void ap(long arg)          { ans.append(arg); }
          static void ap(String arg)        { ans.append(arg); }
          static void ap(StringBuilder arg) { ans.append(arg); }        


          /*-------------- for input in an array ---------------------*/
          static void inputIntegerArray(int arr[]){
               for(int i=0; i<arr.length; i++)arr[i] = ni();
          }
          static void inputLongArray(long arr[]){
               for(int i=0; i<arr.length; i++)arr[i] = nl(); 
          }
          static void inputStringArray(String arr[]){
               for(int i=0; i<arr.length; i++)arr[i] = ns(); 
          }    
          static void inputDoubleArray(double arr[]){
               for(int i=0; i<arr.length; i++)arr[i] = nd();
          }


          /*-------------- File vs Input ---------------------*/
          static void runFile() throws Exception {
               sc = new Scanner(new FileReader("input.txt"));
               pw = new PrintWriter(new BufferedWriter(new FileWriter("output.txt")));
          }
          static void runIo() throws Exception  {
               pw =new PrintWriter(System.out);
               sc = new Scanner(System.in);
          }

          static boolean isPowerOfTwo (long x) { return x!=0 && ((x&(x-1)) == 0);}

          static int gcd(int a, int b) { if (b == 0) return a;     return gcd(b, a % b); }
          
          static long nCr(long n, long r) { // Combinations
               if (n < r)
                    return 0;
               if (r > n - r) { // because nCr(n, r) == nCr(n, n - r)
                    r = n - r;
               }
               long ans = 1L;
               for (long i = 0; i < r; i++) {
                    ans *= (n - i);
                    ans /= (i + 1);
               }
               return ans;
          }          
          
          static int countDigit(long n){return (int)Math.floor(Math.log10(n) + 1);} 
          
          static boolean isPrime(int n) { 
               if (n <= 1) return false; 
               if (n <= 3) return true; 
               if (n % 2 == 0 || n % 3 == 0) return false; 

               for (int i = 5; i * i <= n; i = i + 6) 
               if (n % i == 0 || n % (i + 2) == 0) 
                    return false; 

               return true; 
          }         

          static boolean sv[] = new boolean[10002];
           

          static void seive() {

                 //true -> not prime
               // false->prime

               sv[0] = sv[1] = true; 
               sv[2] = false;
               for(int i = 0; i< sv.length; i++) {
                    if( !sv[i] && (long)i*(long)i < sv.length ) {
                         for ( int j = i*i; j<sv.length ; j += i ) {                
                          sv[j] = true;
                         }
                    }
               }
 
          }


          static long kadensAlgo(int ar[]) {

               int n = ar.length;
    
               long pre = ar[0];
               long ans = ar[0];                

               for(int i = 1; i<n; i++) {

                    pre = Math.max(pre + ar[i], ar[i]);
                    ans = Math.max(pre, ans);

               }

               return ans;
          }


          static long  binpow( long a,   long b) {
               long res = 1;
               while (b > 0) {
                    if ( (b & 1) > 0){
                    res = (res * a)%mod;
               }
               a = (a * a)%mod;
               b >>= 1;
               }

               return res;
          }

          static long factorial(long n)  {
               long res = 1, i;
               for (i = 2; i <= n; i++){
                    res  =  ((res%mod) * (i%mod))%mod;
               }          
               return res;
          }

          static int lowerBund(int ar[], int v) {

               int n = ar.length;
               int l = 0;
               int r = n-1;
               boolean found = false;

               while( l < r ) {

                    int m = l+(r-l)/2;

                    if( ar[m] >= v ) {
                         if( ar[m] == v) 
                              found = true;
                         r = m;
                    }
                    else 
                         l = m+1;
               }

               return found ? l : (-1-l);
          }          

          static int upperBound(int ar[], int v ) {

               int n = ar.length;
               int l = 0;
               int r = n;
               boolean found = false;

               while( l < r ) {

                    int m = l+(r-l)/2;  

                    if( ar[m] <= v ) {
                         l = m+1;
                    }
                    else
                         r = m;
               }

               return r;
          }

  
          static class Pair {
               
               int d, k, f;
               Pair(int d, int k, int f ){
                    this.d = d;
                    this.f = f;  
                    this.k = k;
               }
          }
     
     public static void main(String[] args)  throws Exception {

          // runFile();  
  
          runIo();              

          int t;
          t = 1;
  
          t =  sc.nextInt();
                
          ans = new StringBuilder();
          
          while( t-- > 0 ) {   
               solve();
          }                
          
          pn(ans+""); 
 
     } 

     
 
     public static void solve() {          
               
          int n = ni();
          int ar[] = new int[n];
          inputIntegerArray(ar);
          int min = ar[0];
          int max = ar[0];
          int a = 0, b= 0 ;
          for(int i = 1; i<n; i++) {
               if(min > ar[i] ) {
                    min = ar[i];
                    a = i;
               }
               if(max < ar[i] ) {
                    max = ar[i];
                    b = i;
               }               
          }
 

          int ans = 0;
 
          ans = Math.max(a+1, b+1);
          ans = Math.min(ans, Math.max(n-a, n-b));
          if( a > b ) {
               int t = a;
               a = b;
               b = t;
          }

          ans = Math.min(ans, 1+a+n-b);




           


          ap(ans+"\n");


 
     
     }




 
          
} 


 

 