#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
void solve() {
ll n;
cin >> n;
ll res = 0;
ll low = LLONG_MAX, high = 0;
ll x;
for (ll i = 0; i < n; i++) {
cin >> x;
low = min(low, x);
high = max(high, x);
bool ok = false;
if (low == 1 && high == n && i == 1) ok = true;
else if (high == low + i && (low == 1 || high == n)) ok = true;
else if (high == low + i && high == n - 1 && low == 2) ok = true;
else if (low == 1 && high == (n - (n % 2 == 0)) && high == (low + 2 * i)) ok = true;
else if (low == 2 && high == (n - (n % 2 == 1)) && high == (low + 2 * i)) ok = true;
if (ok) res++;
}
res--;
cout << res << endl;
}
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
ll T;
cin >> T;
for (ll i = 0; i < T; i++)
solve();
return 0;
}