#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 1;
int n, c[N], Next[N], last[N], dp[N];
int calc(int at) {
if (at == n - 1)
return 0;
int &res = dp[at];
if (res != -1)
return res;
res = calc(at + 1) + 1;
if (Next[at] != -1)
res = min(res, calc(Next[at]) + 1);
return res;
}
int main(int argc, char **argv) {
int t;
scanf("%d", &t);
while (t-- != 0) {
scanf("%d", &n);
for (int i = 0; i < n; ++i)
scanf("%d", &c[i]);
memset(dp, -1, sizeof dp);
memset(last, -1, sizeof last);
for (int i = n - 1; i >= 0; --i) {
Next[i] = last[c[i]];
last[c[i]] = i;
}
printf("%d\n", calc(0));
}
return 0;
}
I2luY2x1ZGUgPGJpdHMvc3RkYysrLmg+CnVzaW5nIG5hbWVzcGFjZSBzdGQ7Cgpjb25zdCBpbnQgTiA9IDJlNSArIDE7CmludCBuLCBjW05dLCBOZXh0W05dLCBsYXN0W05dLCBkcFtOXTsKCmludCBjYWxjKGludCBhdCkgewoJaWYgKGF0ID09IG4gLSAxKQoJCXJldHVybiAwOwoJaW50ICZyZXMgPSBkcFthdF07CglpZiAocmVzICE9IC0xKQoJCXJldHVybiByZXM7CglyZXMgPSBjYWxjKGF0ICsgMSkgKyAxOwoJaWYgKE5leHRbYXRdICE9IC0xKQoJCXJlcyA9IG1pbihyZXMsIGNhbGMoTmV4dFthdF0pICsgMSk7CglyZXR1cm4gcmVzOwp9CgppbnQgbWFpbihpbnQgYXJnYywgY2hhciAqKmFyZ3YpIHsKCWludCB0OwoJc2NhbmYoIiVkIiwgJnQpOwoJd2hpbGUgKHQtLSAhPSAwKSB7CgkJc2NhbmYoIiVkIiwgJm4pOwoJCWZvciAoaW50IGkgPSAwOyBpIDwgbjsgKytpKQoJCQlzY2FuZigiJWQiLCAmY1tpXSk7CgkJbWVtc2V0KGRwLCAtMSwgc2l6ZW9mIGRwKTsKCQltZW1zZXQobGFzdCwgLTEsIHNpemVvZiBsYXN0KTsKCQlmb3IgKGludCBpID0gbiAtIDE7IGkgPj0gMDsgLS1pKSB7CgkJCU5leHRbaV0gPSBsYXN0W2NbaV1dOwoJCQlsYXN0W2NbaV1dID0gaTsKCQl9CgkJcHJpbnRmKCIlZFxuIiwgY2FsYygwKSk7Cgl9CglyZXR1cm4gMDsKfQ==