#include <bits/stdc++.h>
using namespace std;
using vi = vector<int>;
int main(){
ios::sync_with_stdio(false);
cin.tie(nullptr);
int t;
cin >> t;
while (t--) {
int n;
cin >> n;
vector<int>a(n);
for (int i = 0; i < n; i++) {
cin >> a[i];
}
// 1) Build, for each value v, the sorted list of all positions where v appears
// so that we can find "the first occurrence > x" by binary search.
vector<vi> pos(n+1);
for (int i = 0; i < n; i++) {
pos[a[i]].push_back(i);
}
int ans = 0;
int start = 0;
// We'll keep the distinct‐set of the *previous* segment here:
unordered_set<int> prevDistinct;
while (start < n) {
// If prevDistinct is empty, we can start our new segment with length = 1
int end;
if (prevDistinct.empty()) {
end = start;
}
else {
// Otherwise, we must stretch this segment until *every* v in prevDistinct
// has appeared at least once in [start..end].
// We'll keep a count of which of those we've already seen.
unordered_set<int> covered;
end = start;
bool ok = true;
while (true) {
if (end >= n) {
// we ran off the end without covering prevDistinct:
ok = false;
break;
}
int v = a[end];
if (prevDistinct.count(v))
covered.insert(v);
if (covered.size() == prevDistinct.size())
break;
end++;
}
if (!ok) {
// impossible to build a successor segment that inherits all of prevDistinct
// so we *merge* everything from `start`..`n-1` into the *last* segment and stop
break;
}
}
// [start..end] is our next segment
ans++;
// build its distinct‐set to pass to the following round
unordered_set<int> currDistinct;
for (int i = start; i <= end; i++)
currDistinct.insert(a[i]);
prevDistinct = move(currDistinct);
start = end + 1;
}
// If we exited the loop with start < n, that remainder (from start to n-1)
// needs to be merged into the *last* segment we already counted, so we do *not*
// increment `ans` again. If we exactly consumed to the end, we're done.
// Edge‐case: if we never counted any segment (which only happens if n=0) we’d need one—
// but the constraints guarantee n≥1, so ans≥1 by construction.
cout << ans << "\n";
}
return 0;
}