← Home
#include<bits/stdc++.h>
#define rep(i, j, k) for(int i=j;i<=k;i++)
#define rep1(i, j, k) for(int i=k;i>=j;i--)
#define ll long long
using namespace std;

int T;
const int N=3e5+5;
int n;
int a[N];

int lst[N];

int pre[N], nex[N];

pair<int, int> q[N];
int top;

int main(){
	
	
	scanf("%d", &T);
	while(T--){
		scanf("%d", &n);
		rep(i, 1, n) lst[i]=0;
		rep(i, 1, n){
			scanf("%d", a+i);
			nex[i]=n+1;
			pre[i]=lst[a[i]];
			nex[lst[a[i]]]=i;
			lst[a[i]]=i;
		}
		
		int ans=0;
		q[top=1]={0, n+1};
		rep1(i, 1, n){
			if(nex[i]<q[top].second){
				++ans, q[top=1]={0, i};
			}else{
				while(top>1 && nex[i]>=q[top-1].second && pre[i]<q[top].first) --top;
				++top, q[top]={max(pre[i]+1, q[top-1].first), i};
			}
			while(q[top].first==i) --top;
		}
		
		printf("%d\n", ans);
		
	}
	
	return 0;
}