Problem: You are given a sequence a_1, a_2, …, a_n of non-negative integers.

You need to find the largest number m of triples (i_1, j_1, k_1), (i_2, j_2, k_2), ..., (i_m, j_m, k_m) such that:

  * 1 ≤ i_p < j_p < k_p ≤ n for each p in 1, 2, …, m;
  * a_{i_p} = a_{k_p} = 0, a_{j_p} ≠ 0;
  * all a_{j_1}, a_{j_2}, …, a_{j_m} are different;
  * all i_1, j_1, k_1, i_2, j_2, k_2, …, i_m, j_m, k_m are different.

Input

The first line of input contains one integer t (1 ≤ t ≤ 500 000): the number of test cases.

The first line of each test case contains one integer n (1 ≤ n ≤ 500 000).

The second line contains n integers a_1, a_2, …, a_n (0 ≤ a_i ≤ n).

The total sum of n is at most 500 000.

Output

For each test case, print one integer m: the largest number of proper triples that you can find.

Example

Input


8
1
1
2
0 0
3
0 1 0
6
0 0 1 2 0 0
6
0 1 0 0 1 0
6
0 1 3 2 0 0
6
0 0 0 0 5 0
12
0 1 0 2 2 2 0 0 3 3 4 0


Output


0
0
1
2
1
1
1
2

Note

In the first two test cases, there are not enough elements even for a single triple, so the answer is 0.

In the third test case we can select one triple (1, 2, 3).

In the fourth test case we can select two triples (1, 3, 5) and (2, 4, 6).

In the fifth test case we can select one triple (1, 2, 3). We can't select two triples (1, 2, 3) and (4, 5, 6), because a_2 = a_5.

Solution (in CPP):

Solution:
#include <bits/stdc++.h>
using namespace std;
int mod = 998244353;
int sum(int a, int b) {
  int c = a + b;
  if (c >= mod) {
    c -= mod;
  }
  return c;
}
int dif(int a, int b) {
  int c = a - b;
  if (c < 0) {
    c += mod;
  }
  return c;
}
int mlt(int a, int b) {
  long long c = a * 1LL * b;
  return c % mod;
}
int ibit(int n, int i) { return ((n >> i) & 1); }
void outp1(vector<long long> &ou, string s = " ") {
  cerr << s << endl;
  for (int i = 0; i < ou.size(); i++) {
    cerr << ou[i] << ' ';
  }
  cerr << endl;
}
void outp1(vector<int> &ou, string s = " ") {
  cerr << s << endl;
  for (int i = 0; i < ou.size(); i++) {
    cerr << ou[i] << ' ';
  }
  cerr << endl;
}
void outp2(vector<vector<long long>> &ou, string s = " ") {
  cerr << s << endl;
  for (int i = 0; i < ou.size(); i++) {
    for (int j = 0; j < ou[i].size(); j++) {
      cerr << ou[i][j] << ' ';
    }
    cerr << '\n';
  }
}
int bp(int x, int y) {
  if (y == 0) {
    return 1;
  }
  int a = 0;
  if (!(y % 2)) {
    a = bp(x, y / 2);
  }
  return (y % 2) ? mlt(bp(x, y - 1), x) : mlt(a, a);
}
int obr(int x) { return bp(x, mod - 2); }
const int maxn = 301;
int fact[maxn], ofact[maxn];
void prec() {
  fact[0] = 1;
  ofact[0] = 1;
  for (int i = 1; i < maxn; i++) {
    fact[i] = mlt(fact[i - 1], i);
  }
  ofact[maxn - 1] = obr(fact[maxn - 1]);
  for (int i = maxn - 2; i > 0; i--) {
    ofact[i] = mlt(ofact[i + 1], i + 1);
  }
}
int c(int a, int b) {
  return ((a <= b) && (a >= 0)) ? mlt(fact[b], mlt(ofact[a], ofact[b - a])) : 0;
}
long long inf = 1e18;
struct segtree {
  int depth = 0;
  vector<int> lb, rb, son, pushed, mn;
};
int sml = 1e8;
void rec_init(segtree &s, int l, int r, int num) {
  s.lb[num] = l;
  s.rb[num] = r;
  if (num < (1 << s.depth)) {
    int mid = (l + r) / 2;
    rec_init(s, l, mid, 2 * num);
    rec_init(s, mid, r, 2 * num + 1);
  } else
    s.son[num] = -1;
}
void init(segtree &s, int n) {
  int t = 0, cur = n;
  while (cur > 1) {
    cur = (cur + 1) / 2;
    t++;
  }
  s.depth = t;
  (s.lb).resize(1 << (t + 1));
  s.rb = s.lb;
  s.son = s.lb;
  s.pushed = s.lb;
  s.mn = s.lb;
  rec_init(s, 0, (1 << t), 1);
}
void getmax(segtree &s, int num) {
  s.mn[num] = min(s.mn[2 * num] + s.pushed[2 * num],
                  s.mn[2 * num + 1] + s.pushed[2 * num + 1]);
}
void segadd(segtree &s, int l, int r, int num, int val) {
  if (l == s.lb[num] && r == s.rb[num]) {
    s.pushed[num] += val;
  } else {
    int mid = (s.lb[num] + s.rb[num]) / 2;
    int r1 = min(mid, r), l2 = max(l, mid);
    if (l < r1) segadd(s, l, r1, 2 * num, val);
    if (l2 < r) segadd(s, l2, r, 2 * num + 1, val);
    getmax(s, num);
  }
}
int segmin(segtree &s, int l, int r, int num) {
  if (l == s.lb[num] && r == s.rb[num]) {
    return s.mn[num] + s.pushed[num];
  } else {
    int mid = (s.lb[num] + s.rb[num]) / 2;
    int r1 = min(mid, r), l2 = max(l, mid);
    int val1 = sml;
    if (l < r1) val1 = min(val1, segmin(s, l, r1, 2 * num));
    if (l2 < r) val1 = min(val1, segmin(s, l2, r, 2 * num + 1));
    return val1 + s.pushed[num];
  }
}
int total_smin(segtree &s) {
  int val = segmin(s, 0, 1 << s.depth, 1);
  return val;
}
void solve(istream &cin = std::cin, ostream &cout = std::cout) {
  int n;
  cin >> n;
  vector<int> vals(n), prev(n), used(n + 1, -1);
  int lzero = -1, rzero = -1;
  for (int i = 0; i < n; i++) {
    cin >> vals[i];
    if (!vals[i]) {
      if (lzero == -1) lzero = i;
      rzero = i;
    }
  }
  int cur = -1;
  for (int i = lzero; i < rzero; i++)
    if (vals[i]) cur = 1;
  int zer = 0;
  for (int i = 0; i < n; i++) {
    if (!vals[i]) zer++;
    prev[i] = used[vals[i]];
    used[vals[i]] = i;
  }
  if (cur == -1)
    cout << 0 << '\n';
  else {
    if (zer < 2)
      cout << 0 << '\n';
    else if (zer < 4)
      cout << 1 << '\n';
    else {
      int ans = zer, curzero = 0;
      segtree s;
      init(s, n + 1);
      for (int i = 0; i < n; i++) {
        if (vals[i] != 0) segadd(s, prev[i] + 1, i + 1, 1, 1);
        if (vals[i] == 0) curzero++;
        segadd(s, i + 1, i + 2, 1, curzero);
        ans = min(ans, segmin(s, 0, i + 2, 0) + zer - curzero);
      }
      cout << min(zer / 2, ans) << '\n';
    }
  }
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int tests = 1;
  cin >> tests;
  for (int i = 0; i < tests; i++) solve();
  int n;
  cin >> n;
}