#include <iostream>
#include <set>
#include <vector>
#include <algorithm>
using namespace std;
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
int t;
cin >> t;
while (t--) {
long long n;
cin >> n;
vector<long long> v(n);
set<long long> s;
for (int i = 0; i < n; i++) {
cin >> v[i];
s.insert(v[i]);
}
if (s.size() == n) {cout<<n<<"\n";}
else {
if (v[0] == v[n-1]) {cout<<"1"<<"\n";}
else {
auto it1=v.begin();
auto it2=v.end();
it1=find(v.begin(),v.end(),v[0]);
it2=find(v.begin(),v.end(),v[n-1]);
if (it1!=v.end() || it2!=v.end())
{cout<<"2"<<"\n";}
else cout<<"3"<<"\n";
}
}
}
return 0;
}