#include <bits/stdc++.h>
using namespace std;
long long gcd(long long a, long long b) {
  if (b == 0) return a;
  return gcd(b, a % b);
}
vector<long long> divisor(long long n) {
  vector<long long> ret;
  for (long long i = 1; i * i <= n; i++) {
    if (n % i == 0) {
      ret.push_back(i);
      if (i * i != n) ret.push_back(n / i);
    }
  }
  sort(begin(ret), end(ret));
  return (ret);
}
struct LazySegmentTree {
 private:
  int n;
  vector<int> node, lazy;
  vector<bool> lazyFlag;

 public:
  LazySegmentTree(vector<int> v) {
    int sz = (int)v.size();
    n = 1;
    while (n < sz) n *= 2;
    node.resize(2 * n - 1);
    lazy.resize(2 * n - 1, INT_MAX);
    lazyFlag.resize(2 * n - 1, false);
    for (int i = 0; i < sz; i++) node[i + n - 1] = v[i];
    for (int i = n - 2; i >= 0; i--)
      node[i] = min(node[i * 2 + 1], node[i * 2 + 2]);
  }
  void lazyEvaluate(int k, int l, int r) {
    if (lazyFlag[k]) {
      node[k] = lazy[k];
      if (r - l > 1) {
        lazy[k * 2 + 1] = lazy[k * 2 + 2] = lazy[k];
        lazyFlag[k * 2 + 1] = lazyFlag[k * 2 + 2] = true;
      }
      lazyFlag[k] = false;
    }
  }
  void update(int a, int b, int x, int k = 0, int l = 0, int r = -1) {
    if (r < 0) r = n;
    lazyEvaluate(k, l, r);
    if (b <= l || r <= a) return;
    if (a <= l && r <= b) {
      lazy[k] = x;
      lazyFlag[k] = true;
      lazyEvaluate(k, l, r);
    } else {
      update(a, b, x, 2 * k + 1, l, (l + r) / 2);
      update(a, b, x, 2 * k + 2, (l + r) / 2, r);
      node[k] = min(node[2 * k + 1], node[2 * k + 2]);
    }
  }
  int find(int a, int b, int k = 0, int l = 0, int r = -1) {
    if (r < 0) r = n;
    lazyEvaluate(k, l, r);
    if (b <= l || r <= a) return INT_MAX;
    if (a <= l && r <= b) return node[k];
    int vl = find(a, b, 2 * k + 1, l, (l + r) / 2);
    int vr = find(a, b, 2 * k + 2, (l + r) / 2, r);
    return min(vl, vr);
  }
};
class UnionFind {
 public:
  vector<long long> par;
  vector<long long> siz;
  UnionFind(long long sz_) : par(sz_), siz(sz_, 1LL) {
    for (long long i = 0; i < sz_; ++i) par[i] = i;
  }
  void init(long long sz_) {
    par.resize(sz_);
    siz.assign(sz_, 1LL);
    for (long long i = 0; i < sz_; ++i) par[i] = i;
  }
  long long root(long long x) {
    while (par[x] != x) {
      x = par[x] = par[par[x]];
    }
    return x;
  }
  bool merge(long long x, long long y) {
    x = root(x);
    y = root(y);
    if (x == y) return false;
    if (siz[x] < siz[y]) swap(x, y);
    siz[x] += siz[y];
    par[y] = x;
    return true;
  }
  bool issame(long long x, long long y) { return root(x) == root(y); }
  long long size(long long x) { return siz[root(x)]; }
};
struct segtree {
  int N, dat[4 * 200004];
  segtree() {}
  segtree(int n) {
    N = 1;
    while (N < n) N *= 2;
    for (int i = 0; i < 2 * N - 1; i++) dat[i] = INT_MAX;
  }
  void update(int k, int a) {
    k += N - 1;
    dat[k] = a;
    while (k > 0) {
      k = (k - 1) / 2;
      dat[k] = min(dat[k * 2 + 1], dat[k * 2 + 2]);
    }
  }
  int query(int a, int b) { return query(a, b, 0, 0, N); }
  int query(int a, int b, int k, int l, int r) {
    if (r <= a || b <= l) return INT_MAX;
    if (a <= l && r <= b) return dat[k];
    int m = (l + r) / 2;
    return min(query(a, b, k * 2 + 1, l, m), query(a, b, k * 2 + 2, m, r));
  }
};
struct segtree2 {
  int N, dat[4 * 200004];
  segtree2() {}
  segtree2(int n) {
    N = 1;
    while (N < n) N *= 2;
    for (int i = 0; i < 2 * N - 1; i++) dat[i] = INT_MIN;
  }
  void update(int k, int a) {
    k += N - 1;
    dat[k] = a;
    while (k > 0) {
      k = (k - 1) / 2;
      dat[k] = max(dat[k * 2 + 1], dat[k * 2 + 2]);
    }
  }
  int query(int a, int b) { return query(a, b, 0, 0, N); }
  int query(int a, int b, int k, int l, int r) {
    if (r <= a || b <= l) return INT_MIN;
    if (a <= l && r <= b) return dat[k];
    int m = (l + r) / 2;
    return max(query(a, b, k * 2 + 1, l, m), query(a, b, k * 2 + 2, m, r));
  }
};
long long mod = 1e9 + 7;
long long modinv(long long a, long long m) {
  long long b = m, u = 1, v = 0;
  while (b) {
    long long t = a / b;
    a -= t * b;
    swap(a, b);
    u -= t * v;
    swap(u, v);
  }
  u %= m;
  if (u < 0) u += m;
  return u;
}
class BIT {
 public:
  vector<int> bit;
  int M;
  BIT(int M) : bit(vector<int>(M + 1, 0)), M(M) {}
  int sum(int i) {
    if (i <= 0) return 0;
    if (i > M) return sum(M);
    if (!i) return 0;
    return bit[i] + sum(i - (i & -i));
  }
  void add(int i, int x) {
    if (i > M) return;
    bit[i] += x;
    add(i + (i & -i), x);
  }
};
signed main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int q, n;
  pair<int, int> num[300004];
  int tmp;
  cin >> q;
  while (q--) {
    cin >> n;
    BIT bit(n);
    for (int i = 1; i <= n; i++) {
      num[i] = pair<int, int>(INT_MAX, INT_MIN);
    }
    for (int i = 1; i <= n; i++) {
      cin >> tmp;
      num[tmp].first = min(i, num[tmp].first);
      num[tmp].second = max(i, num[tmp].second);
      if (bit.sum(tmp) - bit.sum(tmp - 1) == 0) bit.add(tmp, 1);
    }
    int s = 1, t = 0;
    int now = 0;
    int ans = n;
    while (s <= n) {
      if (t < s) {
        t = s;
        now = num[s].second;
        while (1) {
          if (t == n) break;
          t += 1;
          if (num[t].first == INT_MAX) continue;
          if (num[t].first < now) {
            t -= 1;
            break;
          }
          now = num[t].second;
        }
      }
      int tmp = 0;
      tmp += bit.sum(s - 1);
      tmp += bit.sum(n) - bit.sum(t);
      ans = min(ans, tmp);
      s += 1;
      while (s <= n && num[s].first == INT_MAX) s += 1;
      if (s == n + 1) break;
    }
    cout << ans << "\n";
  }
}

### Prompt

Please provide a Cpp coded solution to the problem described below:

You are given a sequence a_1, a_2, ..., a_n, consisting of integers.

You can apply the following operation to this sequence: choose some integer x and move all elements equal to x either to the beginning, or to the end of a. Note that you have to move all these elements in one direction in one operation.

For example, if a = [2, 1, 3, 1, 1, 3, 2], you can get the following sequences in one operation (for convenience, denote elements equal to x as x-elements): 

  * [1, 1, 1, 2, 3, 3, 2] if you move all 1-elements to the beginning; 
  * [2, 3, 3, 2, 1, 1, 1] if you move all 1-elements to the end; 
  * [2, 2, 1, 3, 1, 1, 3] if you move all 2-elements to the beginning; 
  * [1, 3, 1, 1, 3, 2, 2] if you move all 2-elements to the end; 
  * [3, 3, 2, 1, 1, 1, 2] if you move all 3-elements to the beginning; 
  * [2, 1, 1, 1, 2, 3, 3] if you move all 3-elements to the end; 



You have to determine the minimum number of such operations so that the sequence a becomes sorted in non-descending order. Non-descending order means that for all i from 2 to n, the condition a_{i-1} ≤ a_i is satisfied.

Note that you have to answer q independent queries.

Input

The first line contains one integer q (1 ≤ q ≤ 3 ⋅ 10^5) — the number of the queries. Each query is represented by two consecutive lines.

The first line of each query contains one integer n (1 ≤ n ≤ 3 ⋅ 10^5) — the number of elements.

The second line of each query contains n integers a_1, a_2, ... , a_n (1 ≤ a_i ≤ n) — the elements.

It is guaranteed that the sum of all n does not exceed 3 ⋅ 10^5.

Output

For each query print one integer — the minimum number of operation for sorting sequence a in non-descending order.

Example

Input


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


Output


2
0
1

Note

In the first query, you can move all 1-elements to the beginning (after that sequence turn into [1, 1, 1, 3, 6, 6, 3]) and then move all 6-elements to the end.

In the second query, the sequence is sorted initially, so the answer is zero.

In the third query, you have to move all 2-elements to the beginning.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
long long gcd(long long a, long long b) {
  if (b == 0) return a;
  return gcd(b, a % b);
}
vector<long long> divisor(long long n) {
  vector<long long> ret;
  for (long long i = 1; i * i <= n; i++) {
    if (n % i == 0) {
      ret.push_back(i);
      if (i * i != n) ret.push_back(n / i);
    }
  }
  sort(begin(ret), end(ret));
  return (ret);
}
struct LazySegmentTree {
 private:
  int n;
  vector<int> node, lazy;
  vector<bool> lazyFlag;

 public:
  LazySegmentTree(vector<int> v) {
    int sz = (int)v.size();
    n = 1;
    while (n < sz) n *= 2;
    node.resize(2 * n - 1);
    lazy.resize(2 * n - 1, INT_MAX);
    lazyFlag.resize(2 * n - 1, false);
    for (int i = 0; i < sz; i++) node[i + n - 1] = v[i];
    for (int i = n - 2; i >= 0; i--)
      node[i] = min(node[i * 2 + 1], node[i * 2 + 2]);
  }
  void lazyEvaluate(int k, int l, int r) {
    if (lazyFlag[k]) {
      node[k] = lazy[k];
      if (r - l > 1) {
        lazy[k * 2 + 1] = lazy[k * 2 + 2] = lazy[k];
        lazyFlag[k * 2 + 1] = lazyFlag[k * 2 + 2] = true;
      }
      lazyFlag[k] = false;
    }
  }
  void update(int a, int b, int x, int k = 0, int l = 0, int r = -1) {
    if (r < 0) r = n;
    lazyEvaluate(k, l, r);
    if (b <= l || r <= a) return;
    if (a <= l && r <= b) {
      lazy[k] = x;
      lazyFlag[k] = true;
      lazyEvaluate(k, l, r);
    } else {
      update(a, b, x, 2 * k + 1, l, (l + r) / 2);
      update(a, b, x, 2 * k + 2, (l + r) / 2, r);
      node[k] = min(node[2 * k + 1], node[2 * k + 2]);
    }
  }
  int find(int a, int b, int k = 0, int l = 0, int r = -1) {
    if (r < 0) r = n;
    lazyEvaluate(k, l, r);
    if (b <= l || r <= a) return INT_MAX;
    if (a <= l && r <= b) return node[k];
    int vl = find(a, b, 2 * k + 1, l, (l + r) / 2);
    int vr = find(a, b, 2 * k + 2, (l + r) / 2, r);
    return min(vl, vr);
  }
};
class UnionFind {
 public:
  vector<long long> par;
  vector<long long> siz;
  UnionFind(long long sz_) : par(sz_), siz(sz_, 1LL) {
    for (long long i = 0; i < sz_; ++i) par[i] = i;
  }
  void init(long long sz_) {
    par.resize(sz_);
    siz.assign(sz_, 1LL);
    for (long long i = 0; i < sz_; ++i) par[i] = i;
  }
  long long root(long long x) {
    while (par[x] != x) {
      x = par[x] = par[par[x]];
    }
    return x;
  }
  bool merge(long long x, long long y) {
    x = root(x);
    y = root(y);
    if (x == y) return false;
    if (siz[x] < siz[y]) swap(x, y);
    siz[x] += siz[y];
    par[y] = x;
    return true;
  }
  bool issame(long long x, long long y) { return root(x) == root(y); }
  long long size(long long x) { return siz[root(x)]; }
};
struct segtree {
  int N, dat[4 * 200004];
  segtree() {}
  segtree(int n) {
    N = 1;
    while (N < n) N *= 2;
    for (int i = 0; i < 2 * N - 1; i++) dat[i] = INT_MAX;
  }
  void update(int k, int a) {
    k += N - 1;
    dat[k] = a;
    while (k > 0) {
      k = (k - 1) / 2;
      dat[k] = min(dat[k * 2 + 1], dat[k * 2 + 2]);
    }
  }
  int query(int a, int b) { return query(a, b, 0, 0, N); }
  int query(int a, int b, int k, int l, int r) {
    if (r <= a || b <= l) return INT_MAX;
    if (a <= l && r <= b) return dat[k];
    int m = (l + r) / 2;
    return min(query(a, b, k * 2 + 1, l, m), query(a, b, k * 2 + 2, m, r));
  }
};
struct segtree2 {
  int N, dat[4 * 200004];
  segtree2() {}
  segtree2(int n) {
    N = 1;
    while (N < n) N *= 2;
    for (int i = 0; i < 2 * N - 1; i++) dat[i] = INT_MIN;
  }
  void update(int k, int a) {
    k += N - 1;
    dat[k] = a;
    while (k > 0) {
      k = (k - 1) / 2;
      dat[k] = max(dat[k * 2 + 1], dat[k * 2 + 2]);
    }
  }
  int query(int a, int b) { return query(a, b, 0, 0, N); }
  int query(int a, int b, int k, int l, int r) {
    if (r <= a || b <= l) return INT_MIN;
    if (a <= l && r <= b) return dat[k];
    int m = (l + r) / 2;
    return max(query(a, b, k * 2 + 1, l, m), query(a, b, k * 2 + 2, m, r));
  }
};
long long mod = 1e9 + 7;
long long modinv(long long a, long long m) {
  long long b = m, u = 1, v = 0;
  while (b) {
    long long t = a / b;
    a -= t * b;
    swap(a, b);
    u -= t * v;
    swap(u, v);
  }
  u %= m;
  if (u < 0) u += m;
  return u;
}
class BIT {
 public:
  vector<int> bit;
  int M;
  BIT(int M) : bit(vector<int>(M + 1, 0)), M(M) {}
  int sum(int i) {
    if (i <= 0) return 0;
    if (i > M) return sum(M);
    if (!i) return 0;
    return bit[i] + sum(i - (i & -i));
  }
  void add(int i, int x) {
    if (i > M) return;
    bit[i] += x;
    add(i + (i & -i), x);
  }
};
signed main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int q, n;
  pair<int, int> num[300004];
  int tmp;
  cin >> q;
  while (q--) {
    cin >> n;
    BIT bit(n);
    for (int i = 1; i <= n; i++) {
      num[i] = pair<int, int>(INT_MAX, INT_MIN);
    }
    for (int i = 1; i <= n; i++) {
      cin >> tmp;
      num[tmp].first = min(i, num[tmp].first);
      num[tmp].second = max(i, num[tmp].second);
      if (bit.sum(tmp) - bit.sum(tmp - 1) == 0) bit.add(tmp, 1);
    }
    int s = 1, t = 0;
    int now = 0;
    int ans = n;
    while (s <= n) {
      if (t < s) {
        t = s;
        now = num[s].second;
        while (1) {
          if (t == n) break;
          t += 1;
          if (num[t].first == INT_MAX) continue;
          if (num[t].first < now) {
            t -= 1;
            break;
          }
          now = num[t].second;
        }
      }
      int tmp = 0;
      tmp += bit.sum(s - 1);
      tmp += bit.sum(n) - bit.sum(t);
      ans = min(ans, tmp);
      s += 1;
      while (s <= n && num[s].first == INT_MAX) s += 1;
      if (s == n + 1) break;
    }
    cout << ans << "\n";
  }
}

```