#include <stdio.h> // include before iostream for faster scanf
#include <iostream>
#include <vector>
#include <string>
#include <map>
#include <unordered_map>
#include <algorithm>
#include <utility>
#include <set>
#include <unordered_set>
#include <cmath>
#include <math.h>
#include <queue>
#include <stdlib.h>
#include <string.h>
#include <sstream>
#include <tuple>
#include <utility>
#include <iomanip>
#include <iterator>
using namespace std;
typedef long long LL;
#define printv(printVec) for (auto printVecIter : (printVec)) cout << printVecIter << " "; cout << endl;
// g++ -Wall -Wshadow -std=c++11 a.cpp && ./a.out
int main() {
std::ios::sync_with_stdio(false);cin.tie(0);
int t;cin>>t;
while(t--) {
int n;cin>>n;
vector<int> cards(n/2);
set<int> cees;
for (int i =0;i<n/2;i++) {
cin>>cards[i];
cees.emplace(cards[i]);
}
sort(cards.begin(), cards.end());
vector<int> ene;
for (int c = 1; c <=n; c++) {
if (!cees.count(c)) {
ene.push_back(c);
}
}
vector<bool> seen(ene.size());
int ans = 0;
for (int i=0; i < cards.size(); i++) {
int j = ene.size() - 1;
while ((j>=0 && ene[j] >= cards[i]) || seen[j]) {
j--;
if (j == -1) break;
}
if (j >= 0) {
ans++;
seen[j] = true;
}
}
cout << ans << endl;
}
}