#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
int T;
cin >> T;
for (int Ti = 0; Ti < T; ++Ti) {
int n;
cin >> n;
int z[n] {};
deque<int> o, t;
for (int i = 0; i < n/2; ++i) {
int x;
cin >> x;
x--;
z[x] = 1;
}
for (int i = 0; i < n; ++i) {
if (z[i]) {
o.push_back(i);
} else {
t.push_back(i);
}
}
int res = 0;
for (int i = 0; i < n/2; ++i) {
if (o.back() > t.back()) {
o.pop_back();
res++;
} else {
o.pop_front();
}
t.pop_back();
}
cout << res << "\n";
}
}