Problem: This is an easy version of the problem. In this version, all numbers in the given array are distinct and the constraints on n are less than in the hard version of the problem.

You are given an array a of n integers (there are no equals elements in the array). You can perform the following operations on array elements:

  1. choose any index i (1 ≤ i ≤ n) and move the element a[i] to the begin of the array; 
  2. choose any index i (1 ≤ i ≤ n) and move the element a[i] to the end of the array. 



For example, if n = 5, a = [4, 7, 2, 3, 9], then the following sequence of operations can be performed: 

  * after performing the operation of the first type to the second element, the array a will become [7, 4, 2, 3, 9]; 
  * after performing the operation of the second type to the second element, the array a will become [7, 2, 3, 9, 4]. 



You can perform operations of any type any number of times in any order.

Find the minimum total number of operations of the first and second type that will make the a array sorted in non-decreasing order. In other words, what is the minimum number of operations that must be performed so the array satisfies the inequalities a[1] ≤ a[2] ≤ … ≤ a[n].

Input

The first line contains a single integer t (1 ≤ t ≤ 100) — the number of test cases in the test. Then t test cases follow.

Each test case starts with a line containing an integer n (1 ≤ n ≤ 3000) — length of the array a.

Then follow n integers a_1, a_2, …, a_n (0 ≤ a_i ≤ 10^9) — an array that needs to be sorted by the given operations. All numbers in the given array are distinct.

The sum of n for all test cases in one test does not exceed 3000.

Output

For each test case output one integer — the minimum total number of operations of the first and second type, which will make the array sorted in non-decreasing order.

Example

Input


4
5
4 7 2 3 9
5
3 5 8 1 7
5
1 4 5 7 12
4
0 2 1 3


Output


2
2
0
2

Note

In the first test case, you first need to move 3, and then 2 to the beginning of the array. Therefore, the desired sequence of operations: [4, 7, 2, 3, 9] → [3, 4, 7, 2, 9] → [2, 3, 4, 7, 9].

In the second test case, you need to move the 1 to the beginning of the array, and the 8 — to the end. Therefore, the desired sequence of operations: [3, 5, 8, 1, 7] → [1, 3, 5, 8, 7] → [1, 3, 5, 7, 8].

In the third test case, the array is already sorted.

Solution (in CPP):

Solution:
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 205;
const long long int inf = 1e12;
const long long int mod = 1000000007;
long long int gc(long long int a, long long int b) {
  if (b == 0) return a;
  return gc(b, a % b);
}
long long int power(long long int x, long long int y, long long int p) {
  long long int res = 1;
  x = x % p;
  if (x == 0) return 0;
  while (y > 0) {
    if (y & 1) res = (res * x) % p;
    y = y >> 1;
    x = (x * x) % p;
  }
  return res;
}
vector<bool> prime(1000005, true);
vector<long long int> v;
void sieve(long long int n) {
  prime[1] = false;
  for (int p = 2; p * p <= n; p++) {
    if (prime[p] == true) {
      for (int i = p * p; i <= n; i += p) prime[i] = false;
    }
  }
  for (int i = 2; i <= n; i++) {
    if (prime[i] == true) v.push_back(i);
  }
}
inline long long int add(long long int a, long long int b) {
  return ((a % mod) + (b % mod)) % mod;
}
inline long long int sub(long long int a, long long int b) {
  return ((a % mod) - (b % mod) + mod) % mod;
}
inline long long int mul(long long int a, long long int b) {
  return ((a % mod) * (b % mod)) % mod;
}
long long int recur(long long int idx, long long int sum,
                    vector<pair<long long int, long long int> >& v,
                    vector<long long int>& b, vector<long long int>& pre,
                    vector<long long int>& dp) {
  if (idx == b.size()) return 0;
  if (dp[idx] != -1) return dp[idx];
  long long int temp = INT_MAX;
  temp = min(temp, recur(idx + 1, sum, v, b, pre, dp) + b[idx]);
  for (int i = 0; i < v.size(); i++) {
    long long int x = v[i].first;
    long long int y = v[i].second;
    if (idx + x - 1 >= b.size()) continue;
    long long int calc = pre[idx + x - 1] - pre[idx + y - 1];
    temp = min(temp, recur(idx + x, sum, v, b, pre, dp) + calc);
  }
  dp[idx] = temp;
  return temp;
}
long long int dfs(long long int src, long long int p, vector<long long int>& a,
                  vector<pair<long long int, long long int> > adj[],
                  vector<long long int>& dp) {
  long long int can1 = 0;
  long long int can2 = 0;
  vector<pair<long long int, long long int> >::iterator it;
  for (it = adj[src].begin(); it != adj[src].end(); it++) {
    if (((*it).first == p)) continue;
    long long int st =
        max(0LL, dfs((*it).first, src, a, adj, dp) - (*it).second);
    if (st > can1) {
      can2 = can1;
      can1 = st;
    } else if (st > can2) {
      can2 = st;
    }
  }
  dp[src] = a[src] + can1 + can2;
  return (max(can1, can2) + a[src]);
}
struct comp1 {
  bool operator()(pair<long long int, long long int>& temp1,
                  pair<long long int, long long int>& temp2) {}
};
bool comp2(pair<long long int, long long int>& temp1,
           pair<long long int, long long int>& temp2) {
  return ((temp1.first < temp2.first) ||
          ((temp1.first == temp2.first) && (temp1.second < temp2.second)));
}
long long int getinv(long long int temp) { return power(temp, mod - 2, mod); }
void computeLPSArray(string pat, long long int M, vector<long long int>& lps) {
  int len = 0;
  lps[0] = 0;
  long long int i = 1;
  while (i < M) {
    if (pat[i] == pat[len]) {
      len++;
      lps[i] = len;
      i++;
    } else {
      if (len != 0) {
        len = lps[len - 1];
      } else {
        lps[i] = 0;
        i++;
      }
    }
  }
}
long long int fin(long long int u, vector<long long int>& parent) {
  if (u == parent[u])
    return u;
  else
    return parent[u] = fin(parent[u], parent);
}
void unio(long long int u, long long int v, vector<long long int>& parent,
          vector<long long int>& ran) {
  u = fin(u, parent);
  v = fin(v, parent);
  if (u == v) return;
  if (ran[u] >= ran[v]) {
    parent[v] = u;
    ran[u] += ran[v];
  } else {
    parent[u] = v;
    ran[v] += ran[u];
  }
}
void update(int x, int delta, vector<long long int>& BIT) {
  long long int n = BIT.size() - 1;
  for (; x <= n; x += x & -x) BIT[x] += delta;
}
int query(int x, vector<long long int>& BIT) {
  int sum = 0;
  for (; x > 0; x -= x & -x) sum += BIT[x];
  return sum;
}
int main() {
  long long int t;
  cin >> t;
  while (t--) {
    long long int n;
    cin >> n;
    long long int a[n];
    vector<long long int> v;
    for (long long int i = 0; i < n; i++) {
      cin >> a[i];
      v.push_back(a[i]);
    }
    sort(v.begin(), v.end());
    vector<long long int> b(n);
    map<long long int, long long int> m;
    vector<bool> vis(n, false);
    for (long long int i = 0; i < n; i++) {
      long long int idx = lower_bound(v.begin(), v.end(), a[i]) - v.begin();
      b[i] = idx;
    }
    set<long long int> s;
    for (long long int i = 0; i < n; i++) {
      s.insert(b[i]);
    }
    vector<long long int> dp(n, 0);
    long long int ans = 0;
    set<long long int>::iterator it;
    map<long long int, long long int> m1;
    long long int last = -1;
    long long int lcount = 0;
    for (long long int i = 0; i < n; i++) {
      if (last == b[i]) {
        lcount++;
      } else {
        lcount = 1;
        last = b[i];
      }
      it = s.lower_bound(b[i]);
      if (it == s.begin()) {
        long long int p = (*it);
        m1[p]++;
        dp[p] = m1[p];
        ans = max(ans, m1[p]);
      } else {
        it--;
        long long int prev = (*it);
        if (m1.find(b[i]) == m1.end()) {
          dp[b[i]] = dp[prev] + 1;
          m1[b[i]]++;
        } else {
          dp[b[i]] = dp[prev] + lcount;
          m1[b[i]]++;
        }
        ans = max(ans, dp[b[i]]);
      }
    }
    cout << n - ans << endl;
  }
}