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
  #include "bits/stdc++.h"
  using namespace std;
  # define endl "\n"
  #define pb emplace_back
  #define mod 1000000007
  int prime[10000001];
  vector<int> primes;
  void prime_seive()
  {
     for(int i=2;i*i<10000001;i++)
     {
        if(!prime[i])
        {
           for(int j=i*i;j<10000001;j+=i)
            prime[j]=1;
        }
     }
  }
  void calc()
  {
    primes.reserve(1000001);
    for(int i=2;i<10000001;i++)
    {
       if(!prime[i])
        primes.push_back(i);
    }
  }
  long long myceil_ll(long long a,long long b)
  {
     return (a+b-1)/b;
  }
  int myceil_int(int a,int b)
  {
     return (a+b-1)/b;
  }   
  bool is_square(long long temp)
  {
     long long po=sqrtl(temp);
     if(po*po==temp)
      return true;
    return false;
  }
//   bool equal(vector<int> diff)
//   {
//      for(int i=1;i<diff.size();i++)
//      {
//        if(diff[i]!=diff[i-1])return false;
//      }
//      return true;
//   }
//   int first_digit(long long num)
//   {
//      int count=0;
//      while(num>=10)
//         num/=10;
//      return num;
//   }
//   long long fact(int num)
//   {
//     long long prod=1;
//     for(int i=2;i<=num;i++)
//     {
//       prod*=i;
//       prod%=mod;
//     }
//     return prod;
//   }
//   long long power(int a,int b)
//   {
//      long long ans=1;
//      for(int i=0;i<b;i++)
//        ans = (long long)ans*a;
//      return ans;
//   }
//   bool cmp(const pair<int, int>& a,const pair<int, int>& b)
//   {
//     return (a.second > b.second);
//   }
//   // Function to sort the map according
//   // to value in a (key-value) pairs
//   void sorte(map<int, int>& M)
//   {
//     // Declare vector of pairs
//     vector<pair<int, int> > A;
//     // Copy key-value pair from Map
//     // to vector of pairs
//     for (auto& it : M) {
//         A.push_back(it);
//     }
//     // Sort using comparator function
//     sort(A.begin(), A.end());
//   }
  bool is_prime(long long num)
  {
     int is=true;
     for(int i=2;i<=sqrt(num);i++)
     {
       if((num%i)==0)
       {
         return false;
       }
     }
     return true;
  } 
 bool is_valid(int row,int col,int n)
 {
    if(row<col || row<0 || row>=n || col<0 || col>=n)
      return false;
    return true;
 }
//  bool sizecom(const vector<int>& v1, const vector<int>& v2)
//  {
//     return v1.size() > v2.size();
//  }
//  void bubble_sort(int arr[],int n)
//  {
//     for(int i=0;i<n;i++)
//     {
//        for(int j=0;j<n-i-1;j++)
//        {
//          if(arr[j]<arr[j+1])
//           swap(arr[j],arr[j+1]);
//        }
//     }
//  }
//  void insertion_sort(int arr[],int n)
//  {
//     for(int i=1;i<n;i++)
//     {
//       int j=i;
//       while(j>0 && arr[j]<arr[j-1])
//         swap(arr[j],arr[j-1]),j--;
//     }
//  }
//  int partition(int arr[],int start,int end)
//  {
//     int pivot = arr[end];
//     int idx = start-1;
//     for(int i=start;i<end;i++)
//     {
//        if(arr[i]<pivot)
//        {
//          idx++;
//          swap(arr[idx],arr[i]);
//        }
//     }
//     swap(arr[idx+1],arr[end]);
//     return idx+1;
//  }
//  void quick_sort(int arr[],int start,int end)
//  {
//     if(start>=end)return;
//     int pi = partition(arr,start,end);
//     quick_sort(arr,start,pi-1);
//     quick_sort(arr,pi+1,end);
//  }
 void dbg_arr(int arr[],int n)
  {
   for(int i=0;i<n;i++)
     cout << arr[i] << " ";
   cout << endl;
  }
  
  void dbg_vec(vector<int>&v)
  {
   for(auto it:v)
     cout << it << " ";
   cout << endl;
  }
 void read_array(int arr[],int n)
 {
   for(int i=0;i<n;i++)
     cin >> arr[i];
 }
 void write_array(int arr[],int n)
 {
   for(int i=0;i<n;i++)
     cout << arr[i] << " ";
   cout << endl;
 }
// int len(long long num)
//   {
//      int count=0;
//      while(num>0)
//      {
//        //count++;
//        count+=(num%10);
//        num/=10;
//      }
//      return count;
//   }
 
 
  void t_c()
  {
     int n;
     cin >> n;
     int arr[n];
     read_array(arr,n);
     int s_idx,l_idx;
     for(int i=0;i<n;i++)
     {
       if(arr[i]==1)
         s_idx = i;
       if(arr[i]==n)
         l_idx = i;
     }
     int c1,c2,c3;
     // cout << l_idx << " " << s_idx << endl;
     int mini = min(s_idx,l_idx);
     int maxi = max(s_idx,l_idx);
     if(mini == s_idx)
     {
        c1 = s_idx+1 + n-l_idx;
        c2 = s_idx+1 + l_idx-s_idx;
        c3 = n-l_idx + abs(s_idx-l_idx);
     }
     else
     {
       c1 = l_idx+1 + n-s_idx;
       c2 = l_idx+1 + s_idx-l_idx;
       c3 = n-s_idx + abs(s_idx-l_idx);
     }
     // cout << c1 << " " << c2 << " " << c3 << endl;
     cout << min({c1,c2,c3}) << endl;
  }
  int main()
  {
   // prime_seive();
   // calc();
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int t=1;
    cin >> t;
    for(int i=0;i<t;i++)
    {
       t_c();
    }
  }