﻿#include <iostream>
#include <string>
#include <cmath>
#include <algorithm>
#include <vector>
#include <fstream>

using namespace std;

typedef long long ll;
typedef long double ld;



int main() {
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	int t;
	cin >> t;
	for (int q = 0; q < t; q++) {
		int n;
		cin >> n;
		vector<int> a(n);
		int res = 0;
		cin >> a[0];
		vector<int> v;
		int cnt = 1;
		for (int i = 1; i < n; ++i) {
			cin >> a[i];
			if (a[i] == a[i - 1]) cnt++;
			else {
				v.push_back(cnt);
				int d = a[i] - a[i - 1];
				if (d > 0) v.resize(v.size() + d - 1, 0);
				cnt = 1;
			}
		}
		v.push_back(cnt);
		v.push_back(0);
		for (int i = v.size() - 1; i > 0; --i) {
			if (v[i - 1] > v[i]) {
				v[i - 1]--;
				v[i]++;
			}
		}
		for (int& i : v) {
			if (i != 0) res++;
		}
		cout << res << '\n';
	}
}