#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define V vector<ll>
#define pb push_back
#define loop(start, end) for (ll i = start; i <= end; i++)
#define rloop(start, end) for (ll i = start; i >= end; i--)
#define pi acos(-1)
#define fast                          \
    ios_base::sync_with_stdio(false); \
    cin.tie(NULL);
#define T     \
    ll t;     \
    cin >> t; \
    while (t--)

///GCD LCM
#define gcd(a, b) __gcd(a, b)
#define lcm(a, b) ((a * b) / __gcd(a, b))

ll gcdExtended(ll a, ll b, ll *x, ll *y)
{
    if (a == 0)
    {
        *x = 0;
        *y = 1;
        return b;
    }

    ll x1, y1; // To store results of recursive call
    ll gcd = gcdExtended(b % a, a, &x1, &y1);

    // Update x and y using results of
    // recursive call
    *x = y1 - (b / a) * x1;
    *y = x1;

    return gcd;
}

void diophantine(ll a, ll b, ll c, ll *c1, ll *c2)
{
    //objective(to find):
    //a*x+b*y=c
    //and return the value of x,y through c1,c2
    ll x, y;
    ll d = gcdExtended(a, b, &x, &y);
    c = c / d;
    *c1 = x * c;
    *c2 = y * c;
}

int main()
{
    T
    {
        ll n, a;
        cin >> n;
        vector<ll> v(n);
        vector<ll> shortV;
        map<ll, ll> mp;

        cin >> v[0];
        mp[v[0]]++;
        shortV.pb(v[0]);
        // cout << mp[v[0]] << " ";

        for (int i = 1; i < n; i++)
        {
            cin >> v[i];
            if (v[i] != v[i - 1])
            {
                mp[v[i]]++;
                shortV.pb(v[i]);
            }

            for (int j = 0; j < 10; j++)
            {
                a = mp[v[i]];
            }
        }

        ll minRes = n+1;
        for (map<ll, ll>::iterator it = mp.begin(); it != mp.end(); it++)
        {
            ll num = it->first;
            ll temp = mp[num];

            if (v[0] == num && v[n - 1] == num)
                temp -= 1;
            else if (v[0] != num && v[n - 1] != num)
                temp += 1;

            if (temp < minRes)
                minRes = temp;
        }

        cout << minRes << endl;
    }
}


#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define V vector<ll>
#define pb push_back
#define loop(start, end) for (ll i = start; i <= end; i++)
#define rloop(start, end) for (ll i = start; i >= end; i--)
#define pi acos(-1)
#define fast                          \
    ios_base::sync_with_stdio(false); \
    cin.tie(NULL);
#define T     \
    ll t;     \
    cin >> t; \
    while (t--)

///GCD LCM
#define gcd(a, b) __gcd(a, b)
#define lcm(a, b) ((a * b) / __gcd(a, b))

ll gcdExtended(ll a, ll b, ll *x, ll *y)
{
    if (a == 0)
    {
        *x = 0;
        *y = 1;
        return b;
    }

    ll x1, y1; // To store results of recursive call
    ll gcd = gcdExtended(b % a, a, &x1, &y1);

    // Update x and y using results of
    // recursive call
    *x = y1 - (b / a) * x1;
    *y = x1;

    return gcd;
}

void diophantine(ll a, ll b, ll c, ll *c1, ll *c2)
{
    //objective(to find):
    //a*x+b*y=c
    //and return the value of x,y through c1,c2
    ll x, y;
    ll d = gcdExtended(a, b, &x, &y);
    c = c / d;
    *c1 = x * c;
    *c2 = y * c;
}

int main()
{
    T
    {
        ll n, a;
        cin >> n;
        vector<ll> v(n);
        vector<ll> shortV;
        map<ll, ll> mp;

        cin >> v[0];
        mp[v[0]]++;
        shortV.pb(v[0]);
        // cout << mp[v[0]] << " ";

        for (int i = 1; i < n; i++)
        {
            cin >> v[i];
            if (v[i] != v[i - 1])
            {
                mp[v[i]]++;
                shortV.pb(v[i]);
            }

            for (int j = 0; j < 10000; j++)
            {
                a = mp[v[i]];
            }
        }

        ll minRes = n+1;
        for (map<ll, ll>::iterator it = mp.begin(); it != mp.end(); it++)
        {
            ll num = it->first;
            ll temp = mp[num];

            if (v[0] == num && v[n - 1] == num)
                temp -= 1;
            else if (v[0] != num && v[n - 1] != num)
                temp += 1;

            if (temp < minRes)
                minRes = temp;
        }

        cout << minRes << endl;
    }
}


#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define V vector<ll>
#define pb push_back
#define loop(start, end) for (ll i = start; i <= end; i++)
#define rloop(start, end) for (ll i = start; i >= end; i--)
#define pi acos(-1)
#define fast                          \
    ios_base::sync_with_stdio(false); \
    cin.tie(NULL);
#define T     \
    ll t;     \
    cin >> t; \
    while (t--)

///GCD LCM
#define gcd(a, b) __gcd(a, b)
#define lcm(a, b) ((a * b) / __gcd(a, b))

ll gcdExtended(ll a, ll b, ll *x, ll *y)
{
    if (a == 0)
    {
        *x = 0;
        *y = 1;
        return b;
    }

    ll x1, y1; // To store results of recursive call
    ll gcd = gcdExtended(b % a, a, &x1, &y1);

    // Update x and y using results of
    // recursive call
    *x = y1 - (b / a) * x1;
    *y = x1;

    return gcd;
}

void diophantine(ll a, ll b, ll c, ll *c1, ll *c2)
{
    //objective(to find):
    //a*x+b*y=c
    //and return the value of x,y through c1,c2
    ll x, y;
    ll d = gcdExtended(a, b, &x, &y);
    c = c / d;
    *c1 = x * c;
    *c2 = y * c;
}

int main()
{
    T
    {
        ll n, a;
        cin >> n;
        vector<ll> v(n);
        vector<ll> shortV;
        map<ll, ll> mp;

        cin >> v[0];
        mp[v[0]]++;
        shortV.pb(v[0]);
        // cout << mp[v[0]] << " ";

        for (int i = 1; i < n; i++)
        {
            cin >> v[i];
            if (v[i] != v[i - 1])
            {
                mp[v[i]]++;
                shortV.pb(v[i]);
            }

            for (int j = 0; j < 1000; j++)
            {
                a = mp[v[i]];
            }
        }

        ll minRes = n+1;
        for (map<ll, ll>::iterator it = mp.begin(); it != mp.end(); it++)
        {
            ll num = it->first;
            ll temp = mp[num];

            if (v[0] == num && v[n - 1] == num)
                temp -= 1;
            else if (v[0] != num && v[n - 1] != num)
                temp += 1;

            if (temp < minRes)
                minRes = temp;
        }

        cout << minRes << endl;
    }
}


#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define V vector<ll>
#define pb push_back
#define loop(start, end) for (ll i = start; i <= end; i++)
#define rloop(start, end) for (ll i = start; i >= end; i--)
#define pi acos(-1)
#define fast                          \
    ios_base::sync_with_stdio(false); \
    cin.tie(NULL);
#define T     \
    ll t;     \
    cin >> t; \
    while (t--)

///GCD LCM
#define gcd(a, b) __gcd(a, b)
#define lcm(a, b) ((a * b) / __gcd(a, b))

ll gcdExtended(ll a, ll b, ll *x, ll *y)
{
    if (a == 0)
    {
        *x = 0;
        *y = 1;
        return b;
    }

    ll x1, y1; // To store results of recursive call
    ll gcd = gcdExtended(b % a, a, &x1, &y1);

    // Update x and y using results of
    // recursive call
    *x = y1 - (b / a) * x1;
    *y = x1;

    return gcd;
}

void diophantine(ll a, ll b, ll c, ll *c1, ll *c2)
{
    //objective(to find):
    //a*x+b*y=c
    //and return the value of x,y through c1,c2
    ll x, y;
    ll d = gcdExtended(a, b, &x, &y);
    c = c / d;
    *c1 = x * c;
    *c2 = y * c;
}

int main()
{
    T
    {
        ll n, a;
        cin >> n;
        vector<ll> v(n);
        vector<ll> shortV;
        map<ll, ll> mp;

        cin >> v[0];
        mp[v[0]]++;
        shortV.pb(v[0]);
        // cout << mp[v[0]] << " ";

        for (int i = 1; i < n; i++)
        {
            cin >> v[i];
            if (v[i] != v[i - 1])
            {
                mp[v[i]]++;
                shortV.pb(v[i]);
            }

            for (int i = 0; i < 10; i++)
            {
                a = mp[v[i]];
            }
        }

        ll minRes = n+1;
        for (map<ll, ll>::iterator it = mp.begin(); it != mp.end(); it++)
        {
            ll num = it->first;
            ll temp = mp[num];

            if (v[0] == num && v[n - 1] == num)
                temp -= 1;
            else if (v[0] != num && v[n - 1] != num)
                temp += 1;

            if (temp < minRes)
                minRes = temp;
        }

        cout << minRes << endl;
    }
}


#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define V vector<ll>
#define pb push_back
#define loop(start, end) for (ll i = start; i <= end; i++)
#define rloop(start, end) for (ll i = start; i >= end; i--)
#define pi acos(-1)
#define fast                          \
    ios_base::sync_with_stdio(false); \
    cin.tie(NULL);
#define T     \
    ll t;     \
    cin >> t; \
    while (t--)

///GCD LCM
#define gcd(a, b) __gcd(a, b)
#define lcm(a, b) ((a * b) / __gcd(a, b))

ll gcdExtended(ll a, ll b, ll *x, ll *y)
{
    if (a == 0)
    {
        *x = 0;
        *y = 1;
        return b;
    }

    ll x1, y1; // To store results of recursive call
    ll gcd = gcdExtended(b % a, a, &x1, &y1);

    // Update x and y using results of
    // recursive call
    *x = y1 - (b / a) * x1;
    *y = x1;

    return gcd;
}

void diophantine(ll a, ll b, ll c, ll *c1, ll *c2)
{
    //objective(to find):
    //a*x+b*y=c
    //and return the value of x,y through c1,c2
    ll x, y;
    ll d = gcdExtended(a, b, &x, &y);
    c = c / d;
    *c1 = x * c;
    *c2 = y * c;
}

int main()
{
    T
    {
        ll n, a;
        cin >> n;
        vector<ll> v(n);
        vector<ll> shortV;
        map<ll, ll> mp;

        cin >> v[0];
        mp[v[0]]++;
        shortV.pb(v[0]);
        // cout << mp[v[0]] << " ";

        for (int i = 1; i < n; i++)
        {
            cin >> v[i];
            if (v[i] != v[i - 1])
            {
                mp[v[i]]++;
                shortV.pb(v[i]);
            }

            for (int j = 0; j < 100; j++)
            {
                a = mp[v[i]];
            }
        }

        ll minRes = n+1;
        for (map<ll, ll>::iterator it = mp.begin(); it != mp.end(); it++)
        {
            ll num = it->first;
            ll temp = mp[num];

            if (v[0] == num && v[n - 1] == num)
                temp -= 1;
            else if (v[0] != num && v[n - 1] != num)
                temp += 1;

            if (temp < minRes)
                minRes = temp;
        }

        cout << minRes << endl;
    }
}


#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define V vector<ll>
#define pb push_back
#define loop(start, end) for (ll i = start; i <= end; i++)
#define rloop(start, end) for (ll i = start; i >= end; i--)
#define pi acos(-1)
#define fast                          \
    ios_base::sync_with_stdio(false); \
    cin.tie(NULL);
#define T     \
    ll t;     \
    cin >> t; \
    while (t--)

///GCD LCM
#define gcd(a, b) __gcd(a, b)
#define lcm(a, b) ((a * b) / __gcd(a, b))

ll gcdExtended(ll a, ll b, ll *x, ll *y)
{
    if (a == 0)
    {
        *x = 0;
        *y = 1;
        return b;
    }

    ll x1, y1; // To store results of recursive call
    ll gcd = gcdExtended(b % a, a, &x1, &y1);

    // Update x and y using results of
    // recursive call
    *x = y1 - (b / a) * x1;
    *y = x1;

    return gcd;
}

void diophantine(ll a, ll b, ll c, ll *c1, ll *c2)
{
    //objective(to find):
    //a*x+b*y=c
    //and return the value of x,y through c1,c2
    ll x, y;
    ll d = gcdExtended(a, b, &x, &y);
    c = c / d;
    *c1 = x * c;
    *c2 = y * c;
}

int main()
{
    T
    {
        ll n, a;
        cin >> n;
        vector<ll> v(n);
        vector<ll> shortV;
        map<ll, ll> mp;

        cin >> v[0];
        mp[v[0]]++;
        shortV.pb(v[0]);
        // cout << mp[v[0]] << " ";

        for (int i = 1; i < n; i++)
        {
            cin >> v[i];
            if (v[i] != v[i - 1])
            {
                mp[v[i]]++;
                shortV.pb(v[i]);
            }
            a = mp[v[i]];
        }
        // cout << endl;
        // for (int i = 0; i < shortV.size(); i++)
        // {
        //     cout << shortV[i] << " ";
        // }
        // cout << endl;

        ll minRes = n+1;
        for (map<ll, ll>::iterator it = mp.begin(); it != mp.end(); it++)
        {
            ll num = it->first;
            ll temp = mp[num];

            if (v[0] == num && v[n - 1] == num)
                temp -= 1;
            else if (v[0] != num && v[n - 1] != num)
                temp += 1;

            if (temp < minRes)
                minRes = temp;
        }

        cout << minRes << endl;
    }
}


#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define V vector<ll>
#define pb push_back
#define loop(start, end) for (ll i = start; i <= end; i++)
#define rloop(start, end) for (ll i = start; i >= end; i--)
#define pi acos(-1)
#define fast                          \
    ios_base::sync_with_stdio(false); \
    cin.tie(NULL);
#define T     \
    ll t;     \
    cin >> t; \
    while (t--)

///GCD LCM
#define gcd(a, b) __gcd(a, b)
#define lcm(a, b) ((a * b) / __gcd(a, b))

ll gcdExtended(ll a, ll b, ll *x, ll *y)
{
    if (a == 0)
    {
        *x = 0;
        *y = 1;
        return b;
    }

    ll x1, y1; // To store results of recursive call
    ll gcd = gcdExtended(b % a, a, &x1, &y1);

    // Update x and y using results of
    // recursive call
    *x = y1 - (b / a) * x1;
    *y = x1;

    return gcd;
}

void diophantine(ll a, ll b, ll c, ll *c1, ll *c2)
{
    //objective(to find):
    //a*x+b*y=c
    //and return the value of x,y through c1,c2
    ll x, y;
    ll d = gcdExtended(a, b, &x, &y);
    c = c / d;
    *c1 = x * c;
    *c2 = y * c;
}

int main()
{
    T
    {
        ll n, a;
        cin >> n;
        vector<ll> v(n);
        vector<ll> shortV;
        map<ll, ll> mp;

        cin >> v[0];
        mp[v[0]]++;
        shortV.pb(v[0]);
        // cout << mp[v[0]] << " ";

        for (int i = 1; i < n; i++)
        {
            cin >> v[i];
            if (v[i] != v[i - 1])
            {
                mp[v[i]]++;
                shortV.pb(v[i]);
            }
            a = mp[v[i]];
            a = mp[v[i]];
            a = mp[v[i]];
            a = mp[v[i]];
            a = mp[v[i]];
            a = mp[v[i]];
            a = mp[v[i]];
            a = mp[v[i]];
        }

        ll minRes = n+1;
        for (map<ll, ll>::iterator it = mp.begin(); it != mp.end(); it++)
        {
            ll num = it->first;
            ll temp = mp[num];

            if (v[0] == num && v[n - 1] == num)
                temp -= 1;
            else if (v[0] != num && v[n - 1] != num)
                temp += 1;

            if (temp < minRes)
                minRes = temp;
        }

        cout << minRes << endl;
    }
}


#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define V vector<ll>
#define pb push_back
#define loop(start, end) for (ll i = start; i <= end; i++)
#define rloop(start, end) for (ll i = start; i >= end; i--)
#define pi acos(-1)
#define fast                          \
    ios_base::sync_with_stdio(false); \
    cin.tie(NULL);
#define T     \
    ll t;     \
    cin >> t; \
    while (t--)

///GCD LCM
#define gcd(a, b) __gcd(a, b)
#define lcm(a, b) ((a * b) / __gcd(a, b))

ll gcdExtended(ll a, ll b, ll *x, ll *y)
{
    if (a == 0)
    {
        *x = 0;
        *y = 1;
        return b;
    }

    ll x1, y1; // To store results of recursive call
    ll gcd = gcdExtended(b % a, a, &x1, &y1);

    // Update x and y using results of
    // recursive call
    *x = y1 - (b / a) * x1;
    *y = x1;

    return gcd;
}

void diophantine(ll a, ll b, ll c, ll *c1, ll *c2)
{
    //objective(to find):
    //a*x+b*y=c
    //and return the value of x,y through c1,c2
    ll x, y;
    ll d = gcdExtended(a, b, &x, &y);
    c = c / d;
    *c1 = x * c;
    *c2 = y * c;
}

int main()
{
    T
    {
        ll n, a;
        cin >> n;
        vector<ll> v(n);
        vector<ll> shortV;
        map<ll, ll> mp;

        cin >> v[0];
        mp[v[0]]++;
        shortV.pb(v[0]);
        // cout << mp[v[0]] << " ";

        for (int i = 1; i < n; i++)
        {
            cin >> v[i];
            if (v[i] != v[i - 1])
            {
                mp[v[i]]++;
                shortV.pb(v[i]);
            }

            for (int j = 0; j < 110; j++)
            {
                a = mp[v[i]];
            }
        }

        ll minRes = n+1;
        for (map<ll, ll>::iterator it = mp.begin(); it != mp.end(); it++)
        {
            ll num = it->first;
            ll temp = mp[num];

            if (v[0] == num && v[n - 1] == num)
                temp -= 1;
            else if (v[0] != num && v[n - 1] != num)
                temp += 1;

            if (temp < minRes)
                minRes = temp;
        }

        cout << minRes << endl;
    }
}


#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define V vector<ll>
#define pb push_back
#define loop(start, end) for (ll i = start; i <= end; i++)
#define rloop(start, end) for (ll i = start; i >= end; i--)
#define pi acos(-1)
#define fast                          \
    ios_base::sync_with_stdio(false); \
    cin.tie(NULL);
#define T     \
    ll t;     \
    cin >> t; \
    while (t--)

///GCD LCM
#define gcd(a, b) __gcd(a, b)
#define lcm(a, b) ((a * b) / __gcd(a, b))

ll gcdExtended(ll a, ll b, ll *x, ll *y)
{
    if (a == 0)
    {
        *x = 0;
        *y = 1;
        return b;
    }

    ll x1, y1; // To store results of recursive call
    ll gcd = gcdExtended(b % a, a, &x1, &y1);

    // Update x and y using results of
    // recursive call
    *x = y1 - (b / a) * x1;
    *y = x1;

    return gcd;
}

void diophantine(ll a, ll b, ll c, ll *c1, ll *c2)
{
    //objective(to find):
    //a*x+b*y=c
    //and return the value of x,y through c1,c2
    ll x, y;
    ll d = gcdExtended(a, b, &x, &y);
    c = c / d;
    *c1 = x * c;
    *c2 = y * c;
}

int main()
{
    T
    {
        ll n, a;
        cin >> n;
        vector<ll> v(n);
        vector<ll> shortV;
        map<ll, ll> mp;

        cin >> v[0];
        mp[v[0]]++;
        shortV.pb(v[0]);
        // cout << mp[v[0]] << " ";

        for (int i = 1; i < n; i++)
        {
            cin >> v[i];
            if (v[i] != v[i - 1])
            {
                mp[v[i]]++;
                shortV.pb(v[i]);
            }

            for (int j = 0; j < 120; j++)
            {
                a = mp[v[i]];
            }
        }

        ll minRes = n+1;
        for (map<ll, ll>::iterator it = mp.begin(); it != mp.end(); it++)
        {
            ll num = it->first;
            ll temp = mp[num];

            if (v[0] == num && v[n - 1] == num)
                temp -= 1;
            else if (v[0] != num && v[n - 1] != num)
                temp += 1;

            if (temp < minRes)
                minRes = temp;
        }

        cout << minRes << endl;
    }
}


#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define V vector<ll>
#define pb push_back
#define loop(start, end) for (ll i = start; i <= end; i++)
#define rloop(start, end) for (ll i = start; i >= end; i--)
#define pi acos(-1)
#define fast                          \
    ios_base::sync_with_stdio(false); \
    cin.tie(NULL);
#define T     \
    ll t;     \
    cin >> t; \
    while (t--)

///GCD LCM
#define gcd(a, b) __gcd(a, b)
#define lcm(a, b) ((a * b) / __gcd(a, b))

ll gcdExtended(ll a, ll b, ll *x, ll *y)
{
    if (a == 0)
    {
        *x = 0;
        *y = 1;
        return b;
    }

    ll x1, y1; // To store results of recursive call
    ll gcd = gcdExtended(b % a, a, &x1, &y1);

    // Update x and y using results of
    // recursive call
    *x = y1 - (b / a) * x1;
    *y = x1;

    return gcd;
}

void diophantine(ll a, ll b, ll c, ll *c1, ll *c2)
{
    //objective(to find):
    //a*x+b*y=c
    //and return the value of x,y through c1,c2
    ll x, y;
    ll d = gcdExtended(a, b, &x, &y);
    c = c / d;
    *c1 = x * c;
    *c2 = y * c;
}

int main()
{
    T
    {
        ll n, a;
        cin >> n;
        vector<ll> v(n);
        vector<ll> shortV;
        map<ll, ll> mp;

        cin >> v[0];
        mp[v[0]]++;
        shortV.pb(v[0]);
        // cout << mp[v[0]] << " ";

        for (int i = 1; i < n; i++)
        {
            cin >> v[i];
            if (v[i] != v[i - 1])
            {
                mp[v[i]]++;
                shortV.pb(v[i]);
            }
            // cout << mp[v[i]] << " ";
        }
        // cout << endl;
        // for (int i = 0; i < shortV.size(); i++)
        // {
        //     cout << shortV[i] << " ";
        // }
        // cout << endl;

        ll minRes = n+1;
        for (map<ll, ll>::iterator it = mp.begin(); it != mp.end(); it++)
        {
            ll num = it->first;
            ll temp = mp[num];

            if (v[0] == num && v[n - 1] == num)
                temp -= 1;
            else if (v[0] != num && v[n - 1] != num)
                temp += 1;

            if (temp < minRes)
                minRes = temp;
        }

        cout << minRes << endl;
    }
}


#include<bits/stdc++.h>

using namespace std;

#define int long long
#define ll long long
#define fast ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define endl '\n'
#define Endl '\n'
#define cont continue
#define gcd(a,b) __gcd(a,b)
#define lcm(a,b) a*b/__gcd(a,b)
#define pb push_back
#define mp make_pair
#define mem(x) memset(x, 0, sizeof(x))
#define YES cout<<"YES"<<endl;
#define NO cout<<"NO"<<endl;

const ll inf=1e18;
const int mod=1e9+7;
inline int bigmod(int B,int P){int R=1;while(P>0){if(P&1){R=(R*B)%mod;}P>>=1;B=(B*B)%mod;}return R;}
const int mxn = 2e5+10;

int Mod(int a) {
	if(a < 0)
		return (a+mod)%mod;
	else return a % mod;
}
int Mul(int a, int b) {
	return Mod(Mod(a) * Mod(b));
}
int Add(int a, int b) {
	return Mod(Mod(a) + Mod(b));
}

/*
//sieve starts here
#define svMX            200005
bitset<svMX>siv;
vector<ll>prime;

void sieve () {
    siv[0] = siv[1] = 1; // 0 and 1 are not prime

    prime.push_back(2); // Only Even Prime
    for ( int i = 4; i <= svMX; i += 2 ) siv[i] = 1; // Remove multiples of 2

    int sqrtn = sqrt ( svMX );
    for ( int i = 3; i <= sqrtn; i += 2 ) {
        if ( siv[i] == 0 ) {
            for ( int j = i * i; j <= svMX; j += 2 * i ) siv[j] = 1;
        }
    }

    for ( int i = 3; i <= svMX; i += 2 ) if ( siv[i] == 0 ) prime.push_back(i);
}
//sieve ends here
*/

//ll fact[mxn];
//ll in_fact[mxn];
//fact[0] = 1;
//for(ll i = 1; i < mxn; i++) {
	//fact[i] = (i*fact[i-1])%mod;
//}
//in_fact[mxn-1] = bigmod(fact[mxn-1],mod-2);
//for(ll i = mxn-2; i >= 0; i--) {
	//in_fact[i] = (in_fact[i+1] * (i+1))%mod;
//}
//ll c(ll n,ll r) {
	//ll ans = (fact[n] * (in_fact[r] * in_fact[n-r]%mod))%mod;
	//return ans;
//}

signed main(){
    fast;
	//freopen ("input.txt", "r", stdin);
	//freopen ("output.txt", "w", stdout);
    int tt = 1;
    cin>>tt;
    for(int tc = 1; tc <= tt; tc++) {
        int n;
        cin>>n;
        int ip[n];
        vector<int>chk[mxn];
        for(int i = 0; i < n; i++) cin>>ip[i];
        for(int i = 0; i < n; i++) {
			if(chk[ip[i]].size()) {
				int lst = chk[ip[i]].back();
				if(i - lst -1) chk[ip[i]].pb(i);
			}
			else chk[ip[i]].pb(i);
		}
		int res = mxn,tmans;
		int vis[mxn] = {0};
		for(int i = 0; i < n; i++) {
			if(!vis[ip[i]]) {
				vis[ip[i]] = 1;
				int ans = 0;
				int siz = chk[ip[i]].size();
				if(chk[ip[i]][0] != 0) ans++;
				if(chk[ip[i]][siz-1] != 0) ans++;
				tmans = siz+ans-1;
				res = min(res,tmans);
			}

		}
		cout<<res<<endl;

    }

return 0;
}


#include<bits/stdc++.h>

using namespace std;

#define int long long
#define ll long long
#define fast ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define endl '\n'
#define Endl '\n'
#define cont continue
#define gcd(a,b) __gcd(a,b)
#define lcm(a,b) a*b/__gcd(a,b)
#define pb push_back
#define mp make_pair
#define mem(x) memset(x, 0, sizeof(x))
#define YES cout<<"YES"<<endl;
#define NO cout<<"NO"<<endl;

const ll inf=1e18;
const int mod=1e9+7;
inline int bigmod(int B,int P){int R=1;while(P>0){if(P&1){R=(R*B)%mod;}P>>=1;B=(B*B)%mod;}return R;}
const int mxn = 2e5+10;

int Mod(int a) {
	if(a < 0)
		return (a+mod)%mod;
	else return a % mod;
}
int Mul(int a, int b) {
	return Mod(Mod(a) * Mod(b));
}
int Add(int a, int b) {
	return Mod(Mod(a) + Mod(b));
}

/*
//sieve starts here
#define svMX            200005
bitset<svMX>siv;
vector<ll>prime;

void sieve () {
    siv[0] = siv[1] = 1; // 0 and 1 are not prime

    prime.push_back(2); // Only Even Prime
    for ( int i = 4; i <= svMX; i += 2 ) siv[i] = 1; // Remove multiples of 2

    int sqrtn = sqrt ( svMX );
    for ( int i = 3; i <= sqrtn; i += 2 ) {
        if ( siv[i] == 0 ) {
            for ( int j = i * i; j <= svMX; j += 2 * i ) siv[j] = 1;
        }
    }

    for ( int i = 3; i <= svMX; i += 2 ) if ( siv[i] == 0 ) prime.push_back(i);
}
//sieve ends here
*/

//ll fact[mxn];
//ll in_fact[mxn];
//fact[0] = 1;
//for(ll i = 1; i < mxn; i++) {
	//fact[i] = (i*fact[i-1])%mod;
//}
//in_fact[mxn-1] = bigmod(fact[mxn-1],mod-2);
//for(ll i = mxn-2; i >= 0; i--) {
	//in_fact[i] = (in_fact[i+1] * (i+1))%mod;
//}
//ll c(ll n,ll r) {
	//ll ans = (fact[n] * (in_fact[r] * in_fact[n-r]%mod))%mod;
	//return ans;
//}

signed main(){
    fast;
	//freopen ("input.txt", "r", stdin);
	//freopen ("output.txt", "w", stdout);
    int tt = 1;
    cin>>tt;
    for(int tc = 1; tc <= tt; tc++) {
        int n,f = 0,k = 0,fr = 0;
        cin>>n;
        int ip[n+5];
        //vector<pair<int,int>>finl(mxn);
        map<int,int>finl;
        map<int,int>chk;
        int freq[mxn] = {0};
        for(int i = 1; i <= n; i++) {
			cin>>ip[i];
			freq[ip[i]]++;
			if(chk[ip[i]]) {
				k = 1;
				int dif = i-chk[ip[i]]-1;
				if(dif) {
					f = 1;
					if(finl[ip[i]]) {
						if(finl[ip[i]] > dif) {
							finl[ip[i]] = dif;
						}
					}
					else {
						finl[ip[i]] = dif;
					}
				}
			}
			else fr ++;
			chk[ip[i]] = i;
		}
		int onease = 0;
		for(int i = 1; i < mxn; i++) {
			if(freq[i] == 1) {
				onease = 1;
				break;
			}
		}
		if(onease) {
			cout<<1<<endl;
			cont;
		}
		if(fr == 1) {
			cout<<0<<endl;
			cont;
		}
		if(fr > 1 && f == 0)  {
			cout<<1<<Endl;
			cont;
		}
		//if(k == 0) {
			//cout<<0<<endl;
			//cont;
		//}
		int mx = -1, need = -1,ans = 0;
		for(auto it:finl) {
			if(mx < it.second) {
				mx = it.second;
				need = it.first;
			}
		}
		for(int i = 1; i <= n; i++) {
			if(ip[i] == need) {
				if(i-1) {
					if(ip[i-1] != need) {
						ans++;
					}
				}
			}
		}
		cout<<need<<endl;
		if(ip[n] != need) ans++;
		cout<<ans<<endl;

    }

return 0;
}


#include<bits/stdc++.h>

using namespace std;

#define int long long
#define ll long long
#define fast ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define endl '\n'
#define Endl '\n'
#define cont continue
#define gcd(a,b) __gcd(a,b)
#define lcm(a,b) a*b/__gcd(a,b)
#define pb push_back
#define mp make_pair
#define mem(x) memset(x, 0, sizeof(x))
#define YES cout<<"YES"<<endl;
#define NO cout<<"NO"<<endl;

const ll inf=1e18;
const int mod=1e9+7;
inline int bigmod(int B,int P){int R=1;while(P>0){if(P&1){R=(R*B)%mod;}P>>=1;B=(B*B)%mod;}return R;}
const int mxn = 2e5+10;

int Mod(int a) {
	if(a < 0)
		return (a+mod)%mod;
	else return a % mod;
}
int Mul(int a, int b) {
	return Mod(Mod(a) * Mod(b));
}
int Add(int a, int b) {
	return Mod(Mod(a) + Mod(b));
}

/*
//sieve starts here
#define svMX            200005
bitset<svMX>siv;
vector<ll>prime;

void sieve () {
    siv[0] = siv[1] = 1; // 0 and 1 are not prime

    prime.push_back(2); // Only Even Prime
    for ( int i = 4; i <= svMX; i += 2 ) siv[i] = 1; // Remove multiples of 2

    int sqrtn = sqrt ( svMX );
    for ( int i = 3; i <= sqrtn; i += 2 ) {
        if ( siv[i] == 0 ) {
            for ( int j = i * i; j <= svMX; j += 2 * i ) siv[j] = 1;
        }
    }

    for ( int i = 3; i <= svMX; i += 2 ) if ( siv[i] == 0 ) prime.push_back(i);
}
//sieve ends here
*/

//ll fact[mxn];
//ll in_fact[mxn];
//fact[0] = 1;
//for(ll i = 1; i < mxn; i++) {
	//fact[i] = (i*fact[i-1])%mod;
//}
//in_fact[mxn-1] = bigmod(fact[mxn-1],mod-2);
//for(ll i = mxn-2; i >= 0; i--) {
	//in_fact[i] = (in_fact[i+1] * (i+1))%mod;
//}
//ll c(ll n,ll r) {
	//ll ans = (fact[n] * (in_fact[r] * in_fact[n-r]%mod))%mod;
	//return ans;
//}

signed main(){
    fast;
	//freopen ("input.txt", "r", stdin);
	//freopen ("output.txt", "w", stdout);
    int tt = 1;
    cin>>tt;
    for(int tc = 1; tc <= tt; tc++) {
        int n,f = 0,k = 0;
        cin>>n;
        int ip[n+5];
        //vector<pair<int,int>>finl(mxn);
        map<int,int>finl;
        map<int,int>chk;
        for(int i = 1; i <= n; i++) {
			cin>>ip[i];
			if(chk[ip[i]]) {
				k = 1;
				int dif = i-chk[ip[i]]-1;
				if(dif) {
					f = 1;
					if(finl[ip[i]]) {
						if(finl[ip[i]] > dif) {
							finl[ip[i]] = dif;
						}
					}
					else {
						finl[ip[i]] = dif;
					}
				}
			}
			chk[ip[i]] = i;
		}
		if(k == 1 && f == 0)  {
			cout<<0<<Endl;
			cont;
		}
		if(k == 0) {
			cout<<1<<endl;
			cont;
		}
		int mx = -1, need = -1,ans = 0;
		for(auto it:finl) {
			if(mx < it.second) {
				mx = it.second;
				need = it.first;
			}
		}
		for(int i = 0; i < n; i++) {
			if(ip[i] == need) {
				if(i) {
					if(ip[i-1] != need) {
						ans++;
					}
				}
			}
		}
		//cout<<need<<endl;
		if(ip[n] != need) ans++;
		cout<<ans<<endl;

    }

return 0;
}


#include<bits/stdc++.h>

using namespace std;

#define int long long
#define ll long long
#define fast ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define endl '\n'
#define Endl '\n'
#define cont continue
#define gcd(a,b) __gcd(a,b)
#define lcm(a,b) a*b/__gcd(a,b)
#define pb push_back
#define mp make_pair
#define mem(x) memset(x, 0, sizeof(x))
#define YES cout<<"YES"<<endl;
#define NO cout<<"NO"<<endl;

const ll inf=1e18;
const int mod=1e9+7;
inline int bigmod(int B,int P){int R=1;while(P>0){if(P&1){R=(R*B)%mod;}P>>=1;B=(B*B)%mod;}return R;}
const int mxn = 2e5+10;

int Mod(int a) {
	if(a < 0)
		return (a+mod)%mod;
	else return a % mod;
}
int Mul(int a, int b) {
	return Mod(Mod(a) * Mod(b));
}
int Add(int a, int b) {
	return Mod(Mod(a) + Mod(b));
}

/*
//sieve starts here
#define svMX            200005
bitset<svMX>siv;
vector<ll>prime;

void sieve () {
    siv[0] = siv[1] = 1; // 0 and 1 are not prime

    prime.push_back(2); // Only Even Prime
    for ( int i = 4; i <= svMX; i += 2 ) siv[i] = 1; // Remove multiples of 2

    int sqrtn = sqrt ( svMX );
    for ( int i = 3; i <= sqrtn; i += 2 ) {
        if ( siv[i] == 0 ) {
            for ( int j = i * i; j <= svMX; j += 2 * i ) siv[j] = 1;
        }
    }

    for ( int i = 3; i <= svMX; i += 2 ) if ( siv[i] == 0 ) prime.push_back(i);
}
//sieve ends here
*/

//ll fact[mxn];
//ll in_fact[mxn];
//fact[0] = 1;
//for(ll i = 1; i < mxn; i++) {
	//fact[i] = (i*fact[i-1])%mod;
//}
//in_fact[mxn-1] = bigmod(fact[mxn-1],mod-2);
//for(ll i = mxn-2; i >= 0; i--) {
	//in_fact[i] = (in_fact[i+1] * (i+1))%mod;
//}
//ll c(ll n,ll r) {
	//ll ans = (fact[n] * (in_fact[r] * in_fact[n-r]%mod))%mod;
	//return ans;
//}

vector<int>chk[mxn];
signed main(){
    fast;
	//freopen ("input.txt", "r", stdin);
	//freopen ("output.txt", "w", stdout);
    int tt = 1;
    cin>>tt;
    for(int tc = 1; tc <= tt; tc++) {
        int n;
        cin>>n;
        int ip[n],prev[n+1],cnt[n+1],vis[n+1];
        mem(prev);
        mem(cnt);
        mem(vis);
        for(int i = 0; i < n; i++) {
			cin>>ip[i];
			cnt[ip[i]] += (i-prev[ip[i]]-1 > 0);
			prev[ip[i]] = i;
		}
		for(int i = 0; i < n; i++) {
			if(!vis[ip[i]]) {
				cnt[ip[i]] += (n-prev[ip[i]]-1 > 0);
				vis[ip[i]] = 1;
			}
		}
		int ans = inf;
		for(int i = 0; i< n; i++) {
			ans = min(ans,cnt[ip[i]]);
		}
		cout<<ans<<endl;

    }

return 0;
}


#include<bits/stdc++.h>

using namespace std;

#define int long long
#define ll long long
#define fast ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define endl '\n'
#define Endl '\n'
#define cont continue
#define gcd(a,b) __gcd(a,b)
#define lcm(a,b) a*b/__gcd(a,b)
#define pb push_back
#define mp make_pair
#define mem(x) memset(x, 0, sizeof(x))
#define YES cout<<"YES"<<endl;
#define NO cout<<"NO"<<endl;

const ll inf=1e18;
const int mod=1e9+7;
inline int bigmod(int B,int P){int R=1;while(P>0){if(P&1){R=(R*B)%mod;}P>>=1;B=(B*B)%mod;}return R;}
const int mxn = 2e5+10;

int Mod(int a) {
	if(a < 0)
		return (a+mod)%mod;
	else return a % mod;
}
int Mul(int a, int b) {
	return Mod(Mod(a) * Mod(b));
}
int Add(int a, int b) {
	return Mod(Mod(a) + Mod(b));
}

/*
//sieve starts here
#define svMX            200005
bitset<svMX>siv;
vector<ll>prime;

void sieve () {
    siv[0] = siv[1] = 1; // 0 and 1 are not prime

    prime.push_back(2); // Only Even Prime
    for ( int i = 4; i <= svMX; i += 2 ) siv[i] = 1; // Remove multiples of 2

    int sqrtn = sqrt ( svMX );
    for ( int i = 3; i <= sqrtn; i += 2 ) {
        if ( siv[i] == 0 ) {
            for ( int j = i * i; j <= svMX; j += 2 * i ) siv[j] = 1;
        }
    }

    for ( int i = 3; i <= svMX; i += 2 ) if ( siv[i] == 0 ) prime.push_back(i);
}
//sieve ends here
*/

//ll fact[mxn];
//ll in_fact[mxn];
//fact[0] = 1;
//for(ll i = 1; i < mxn; i++) {
	//fact[i] = (i*fact[i-1])%mod;
//}
//in_fact[mxn-1] = bigmod(fact[mxn-1],mod-2);
//for(ll i = mxn-2; i >= 0; i--) {
	//in_fact[i] = (in_fact[i+1] * (i+1))%mod;
//}
//ll c(ll n,ll r) {
	//ll ans = (fact[n] * (in_fact[r] * in_fact[n-r]%mod))%mod;
	//return ans;
//}

vector<int>chk[mxn];
signed main(){
    fast;
	//freopen ("input.txt", "r", stdin);
	//freopen ("output.txt", "w", stdout);
    int tt = 1;
    cin>>tt;
    for(int tc = 1; tc <= tt; tc++) {
        int n;
        cin>>n;
        int ip[n],prev[n+1],cnt[n+1],vis[n+1];
        for(int i = 0; i < n; i++) {
			cin>>ip[i];
			cnt[ip[i]] += i-prev[ip[i]]-1;
			prev[ip[i]] = i;
		}
		for(int i = 0; i < n; i++) {
			if(!vis[ip[i]]) {
				cnt[ip[i]] += n-prev[ip[i]]-1;
				vis[ip[i]] = 1;
			}
		}
		int ans = inf;
		for(int i = 0; i< n; i++) {
			ans = min(ans,cnt[ip[i]]);
		}
		cout<<ans<<endl;

    }

return 0;
}


#include<bits/stdc++.h>

using namespace std;

#define int long long
#define ll long long
#define fast ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define endl '\n'
#define Endl '\n'
#define cont continue
#define gcd(a,b) __gcd(a,b)
#define lcm(a,b) a*b/__gcd(a,b)
#define pb push_back
#define mp make_pair
#define mem(x) memset(x, 0, sizeof(x))
#define YES cout<<"YES"<<endl;
#define NO cout<<"NO"<<endl;

const ll inf=1e18;
const int mod=1e9+7;
inline int bigmod(int B,int P){int R=1;while(P>0){if(P&1){R=(R*B)%mod;}P>>=1;B=(B*B)%mod;}return R;}
const int mxn = 2e5+10;

int Mod(int a) {
	if(a < 0)
		return (a+mod)%mod;
	else return a % mod;
}
int Mul(int a, int b) {
	return Mod(Mod(a) * Mod(b));
}
int Add(int a, int b) {
	return Mod(Mod(a) + Mod(b));
}

/*
//sieve starts here
#define svMX            200005
bitset<svMX>siv;
vector<ll>prime;

void sieve () {
    siv[0] = siv[1] = 1; // 0 and 1 are not prime

    prime.push_back(2); // Only Even Prime
    for ( int i = 4; i <= svMX; i += 2 ) siv[i] = 1; // Remove multiples of 2

    int sqrtn = sqrt ( svMX );
    for ( int i = 3; i <= sqrtn; i += 2 ) {
        if ( siv[i] == 0 ) {
            for ( int j = i * i; j <= svMX; j += 2 * i ) siv[j] = 1;
        }
    }

    for ( int i = 3; i <= svMX; i += 2 ) if ( siv[i] == 0 ) prime.push_back(i);
}
//sieve ends here
*/

//ll fact[mxn];
//ll in_fact[mxn];
//fact[0] = 1;
//for(ll i = 1; i < mxn; i++) {
	//fact[i] = (i*fact[i-1])%mod;
//}
//in_fact[mxn-1] = bigmod(fact[mxn-1],mod-2);
//for(ll i = mxn-2; i >= 0; i--) {
	//in_fact[i] = (in_fact[i+1] * (i+1))%mod;
//}
//ll c(ll n,ll r) {
	//ll ans = (fact[n] * (in_fact[r] * in_fact[n-r]%mod))%mod;
	//return ans;
//}

vector<int>chk[mxn];
signed main(){
    fast;
	//freopen ("input.txt", "r", stdin);
	//freopen ("output.txt", "w", stdout);
    int tt = 1;
    cin>>tt;
    for(int tc = 1; tc <= tt; tc++) {
        int n;
        cin>>n;
        int ip[n];
        //vector<int>chk[mxn];
        for(int i = 0; i < n; i++) cin>>ip[i];
        for(int i = 0; i < n; i++) {
			if(chk[ip[i]].size()) {
				int lst = chk[ip[i]].back();
				if(i - lst -1) chk[ip[i]].pb(i);
			}
			else chk[ip[i]].pb(i);
		}
		int res = mxn,tmans;
		int vis[mxn] = {0};
		for(int i = 0; i < n; i++) {
			if(!vis[ip[i]]) {
				vis[ip[i]] = 1;
				int ans = 0;
				int siz = chk[ip[i]].size();
				if(chk[ip[i]][0] != 0) ans++;
				if(chk[ip[i]][siz-1] != 0) ans++;
				tmans = siz+ans-1;
				res = min(res,tmans);
			}

		}
		cout<<res<<endl;
		chk.clear();

    }

return 0;
}


#include<bits/stdc++.h>

using namespace std;

#define int long long
#define ll long long
#define fast ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define endl '\n'
#define Endl '\n'
#define cont continue
#define gcd(a,b) __gcd(a,b)
#define lcm(a,b) a*b/__gcd(a,b)
#define pb push_back
#define mp make_pair
#define mem(x) memset(x, 0, sizeof(x))
#define YES cout<<"YES"<<endl;
#define NO cout<<"NO"<<endl;

const ll inf=1e18;
const int mod=1e9+7;
inline int bigmod(int B,int P){int R=1;while(P>0){if(P&1){R=(R*B)%mod;}P>>=1;B=(B*B)%mod;}return R;}
const int mxn = 2e5+10;

int Mod(int a) {
	if(a < 0)
		return (a+mod)%mod;
	else return a % mod;
}
int Mul(int a, int b) {
	return Mod(Mod(a) * Mod(b));
}
int Add(int a, int b) {
	return Mod(Mod(a) + Mod(b));
}

/*
//sieve starts here
#define svMX            200005
bitset<svMX>siv;
vector<ll>prime;

void sieve () {
    siv[0] = siv[1] = 1; // 0 and 1 are not prime

    prime.push_back(2); // Only Even Prime
    for ( int i = 4; i <= svMX; i += 2 ) siv[i] = 1; // Remove multiples of 2

    int sqrtn = sqrt ( svMX );
    for ( int i = 3; i <= sqrtn; i += 2 ) {
        if ( siv[i] == 0 ) {
            for ( int j = i * i; j <= svMX; j += 2 * i ) siv[j] = 1;
        }
    }

    for ( int i = 3; i <= svMX; i += 2 ) if ( siv[i] == 0 ) prime.push_back(i);
}
//sieve ends here
*/

//ll fact[mxn];
//ll in_fact[mxn];
//fact[0] = 1;
//for(ll i = 1; i < mxn; i++) {
	//fact[i] = (i*fact[i-1])%mod;
//}
//in_fact[mxn-1] = bigmod(fact[mxn-1],mod-2);
//for(ll i = mxn-2; i >= 0; i--) {
	//in_fact[i] = (in_fact[i+1] * (i+1))%mod;
//}
//ll c(ll n,ll r) {
	//ll ans = (fact[n] * (in_fact[r] * in_fact[n-r]%mod))%mod;
	//return ans;
//}

vector<int>chk[mxn];
signed main(){
    fast;
	//freopen ("input.txt", "r", stdin);
	//freopen ("output.txt", "w", stdout);
    int tt = 1;
    cin>>tt;
    for(int tc = 1; tc <= tt; tc++) {
        int n;
        cin>>n;
        int ip[n+1],prev[n+1],cnt[n+1],vis[n+1];
        mem(prev);
        mem(cnt);
        mem(vis);
        for(int i = 1; i <= n; i++) {
			cin>>ip[i];
			cnt[ip[i]] += (i-prev[ip[i]]-1 > 0);
			prev[ip[i]] = i;
		}
		for(int i = 1; i <= n; i++) {
			if(!vis[ip[i]]) {
				cnt[ip[i]] += (n+1-prev[ip[i]]-1 > 0);
				vis[ip[i]] = 1;
			}
		}
		int ans = inf;
		for(int i = 1; i <= n; i++) {
			ans = min(ans,cnt[ip[i]]);
		}
		cout<<ans<<endl;

    }

return 0;
}


#include<bits/stdc++.h>

using namespace std;

#define int long long
#define ll long long
#define fast ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define endl '\n'
#define Endl '\n'
#define cont continue
#define gcd(a,b) __gcd(a,b)
#define lcm(a,b) a*b/__gcd(a,b)
#define pb push_back
#define mp make_pair
#define mem(x) memset(x, 0, sizeof(x))
#define YES cout<<"YES"<<endl;
#define NO cout<<"NO"<<endl;

const ll inf=1e18;
const int mod=1e9+7;
inline int bigmod(int B,int P){int R=1;while(P>0){if(P&1){R=(R*B)%mod;}P>>=1;B=(B*B)%mod;}return R;}
const int mxn = 2e5+10;

int Mod(int a) {
	if(a < 0)
		return (a+mod)%mod;
	else return a % mod;
}
int Mul(int a, int b) {
	return Mod(Mod(a) * Mod(b));
}
int Add(int a, int b) {
	return Mod(Mod(a) + Mod(b));
}

/*
//sieve starts here
#define svMX            200005
bitset<svMX>siv;
vector<ll>prime;

void sieve () {
    siv[0] = siv[1] = 1; // 0 and 1 are not prime

    prime.push_back(2); // Only Even Prime
    for ( int i = 4; i <= svMX; i += 2 ) siv[i] = 1; // Remove multiples of 2

    int sqrtn = sqrt ( svMX );
    for ( int i = 3; i <= sqrtn; i += 2 ) {
        if ( siv[i] == 0 ) {
            for ( int j = i * i; j <= svMX; j += 2 * i ) siv[j] = 1;
        }
    }

    for ( int i = 3; i <= svMX; i += 2 ) if ( siv[i] == 0 ) prime.push_back(i);
}
//sieve ends here
*/

//ll fact[mxn];
//ll in_fact[mxn];
//fact[0] = 1;
//for(ll i = 1; i < mxn; i++) {
	//fact[i] = (i*fact[i-1])%mod;
//}
//in_fact[mxn-1] = bigmod(fact[mxn-1],mod-2);
//for(ll i = mxn-2; i >= 0; i--) {
	//in_fact[i] = (in_fact[i+1] * (i+1))%mod;
//}
//ll c(ll n,ll r) {
	//ll ans = (fact[n] * (in_fact[r] * in_fact[n-r]%mod))%mod;
	//return ans;
//}

signed main(){
    fast;
	//freopen ("input.txt", "r", stdin);
	//freopen ("output.txt", "w", stdout);
    int tt = 1;
    cin>>tt;
    for(int tc = 1; tc <= tt; tc++) {
        int n,f = 0,k = 0,fr = 0;
        cin>>n;
        int ip[n+5];
        //vector<pair<int,int>>finl(mxn);
        map<int,int>finl;
        map<int,int>chk;
        int freq[mxn] = {0};
        for(int i = 1; i <= n; i++) {
			cin>>ip[i];
			freq[ip[i]]++;
			if(chk[ip[i]]) {
				k = 1;
				int dif = i-chk[ip[i]]-1;
				if(dif) {
					f = 1;
					if(finl[ip[i]]) {
						if(finl[ip[i]] > dif) {
							finl[ip[i]] = dif;
						}
					}
					else {
						finl[ip[i]] = dif;
					}
				}
			}
			else fr ++;
			chk[ip[i]] = i;
		}
		int onease = 0;
		for(int i = 1; i < mxn; i++) {
			if(freq[i] == 1) {
				onease = 1;
				break;
			}
		}
		if(onease) {
			cout<<1<<endl;
			cont;
		}
		if(fr == 1) {
			cout<<0<<endl;
			cont;
		}
		if(fr > 1 && f == 0)  {
			cout<<1<<Endl;
			cont;
		}
		//if(k == 0) {
			//cout<<0<<endl;
			//cont;
		//}
		int mx = -1, need = -1,ans = 0;
		for(auto it:finl) {
			if(mx < it.second) {
				mx = it.second;
				need = it.first;
			}
		}
		for(int i = 1; i <= n; i++) {
			if(ip[i] == need) {
				if(i-1) {
					if(ip[i-1] != need) {
						ans++;
					}
				}
			}
		}
		//cout<<need<<endl;
		if(ip[n] != need) ans++;
		cout<<ans<<endl;

    }

return 0;
}


#include<bits/stdc++.h>

using namespace std;

#define int long long
#define ll long long
#define fast ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define endl '\n'
#define Endl '\n'
#define cont continue
#define gcd(a,b) __gcd(a,b)
#define lcm(a,b) a*b/__gcd(a,b)
#define pb push_back
#define mp make_pair
#define mem(x) memset(x, 0, sizeof(x))
#define YES cout<<"YES"<<endl;
#define NO cout<<"NO"<<endl;

const ll inf=1e18;
const int mod=1e9+7;
inline int bigmod(int B,int P){int R=1;while(P>0){if(P&1){R=(R*B)%mod;}P>>=1;B=(B*B)%mod;}return R;}
const int mxn = 2e5+10;

int Mod(int a) {
	if(a < 0)
		return (a+mod)%mod;
	else return a % mod;
}
int Mul(int a, int b) {
	return Mod(Mod(a) * Mod(b));
}
int Add(int a, int b) {
	return Mod(Mod(a) + Mod(b));
}

/*
//sieve starts here
#define svMX            200005
bitset<svMX>siv;
vector<ll>prime;

void sieve () {
    siv[0] = siv[1] = 1; // 0 and 1 are not prime

    prime.push_back(2); // Only Even Prime
    for ( int i = 4; i <= svMX; i += 2 ) siv[i] = 1; // Remove multiples of 2

    int sqrtn = sqrt ( svMX );
    for ( int i = 3; i <= sqrtn; i += 2 ) {
        if ( siv[i] == 0 ) {
            for ( int j = i * i; j <= svMX; j += 2 * i ) siv[j] = 1;
        }
    }

    for ( int i = 3; i <= svMX; i += 2 ) if ( siv[i] == 0 ) prime.push_back(i);
}
//sieve ends here
*/

//ll fact[mxn];
//ll in_fact[mxn];
//fact[0] = 1;
//for(ll i = 1; i < mxn; i++) {
	//fact[i] = (i*fact[i-1])%mod;
//}
//in_fact[mxn-1] = bigmod(fact[mxn-1],mod-2);
//for(ll i = mxn-2; i >= 0; i--) {
	//in_fact[i] = (in_fact[i+1] * (i+1))%mod;
//}
//ll c(ll n,ll r) {
	//ll ans = (fact[n] * (in_fact[r] * in_fact[n-r]%mod))%mod;
	//return ans;
//}

signed main(){
    fast;
	//freopen ("input.txt", "r", stdin);
	//freopen ("output.txt", "w", stdout);
    int tt = 1;
    cin>>tt;
    for(int tc = 1; tc <= tt; tc++) {
        int n,f = 0,k = 0,fr = 0;
        cin>>n;
        int ip[n+5];
        //vector<pair<int,int>>finl(mxn);
        map<int,int>finl;
        map<int,int>chk;
        for(int i = 1; i <= n; i++) {
			cin>>ip[i];
			if(chk[ip[i]]) {
				k = 1;
				int dif = i-chk[ip[i]]-1;
				if(dif) {
					f = 1;
					if(finl[ip[i]]) {
						if(finl[ip[i]] > dif) {
							finl[ip[i]] = dif;
						}
					}
					else {
						finl[ip[i]] = dif;
					}
				}
			}
			else fr ++;
			chk[ip[i]] = i;
		}
		if(fr == 1) {
			cout<<0<<endl;
			cont;
		}
		if(fr > 1 && f == 0)  {
			cout<<1<<Endl;
			cont;
		}
		//if(k == 0) {
			//cout<<0<<endl;
			//cont;
		//}
		int mx = -1, need = -1,ans = 0;
		for(auto it:finl) {
			if(mx < it.second) {
				mx = it.second;
				need = it.first;
			}
		}
		for(int i = 1; i <= n; i++) {
			if(ip[i] == need) {
				if(i-1) {
					if(ip[i-1] != need) {
						ans++;
					}
				}
			}
		}
		//cout<<need<<endl;
		if(ip[n] != need) ans++;
		cout<<ans<<endl;

    }

return 0;
}


#include<bits/stdc++.h>

using namespace std;

#define int long long
#define ll long long
#define fast ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define endl '\n'
#define Endl '\n'
#define cont continue
#define gcd(a,b) __gcd(a,b)
#define lcm(a,b) a*b/__gcd(a,b)
#define pb push_back
#define mp make_pair
#define mem(x) memset(x, 0, sizeof(x))
#define YES cout<<"YES"<<endl;
#define NO cout<<"NO"<<endl;

const ll inf=1e18;
const int mod=1e9+7;
inline int bigmod(int B,int P){int R=1;while(P>0){if(P&1){R=(R*B)%mod;}P>>=1;B=(B*B)%mod;}return R;}
const int mxn = 2e5+10;

int Mod(int a) {
	if(a < 0)
		return (a+mod)%mod;
	else return a % mod;
}
int Mul(int a, int b) {
	return Mod(Mod(a) * Mod(b));
}
int Add(int a, int b) {
	return Mod(Mod(a) + Mod(b));
}

/*
//sieve starts here
#define svMX            200005
bitset<svMX>siv;
vector<ll>prime;

void sieve () {
    siv[0] = siv[1] = 1; // 0 and 1 are not prime

    prime.push_back(2); // Only Even Prime
    for ( int i = 4; i <= svMX; i += 2 ) siv[i] = 1; // Remove multiples of 2

    int sqrtn = sqrt ( svMX );
    for ( int i = 3; i <= sqrtn; i += 2 ) {
        if ( siv[i] == 0 ) {
            for ( int j = i * i; j <= svMX; j += 2 * i ) siv[j] = 1;
        }
    }

    for ( int i = 3; i <= svMX; i += 2 ) if ( siv[i] == 0 ) prime.push_back(i);
}
//sieve ends here
*/

//ll fact[mxn];
//ll in_fact[mxn];
//fact[0] = 1;
//for(ll i = 1; i < mxn; i++) {
	//fact[i] = (i*fact[i-1])%mod;
//}
//in_fact[mxn-1] = bigmod(fact[mxn-1],mod-2);
//for(ll i = mxn-2; i >= 0; i--) {
	//in_fact[i] = (in_fact[i+1] * (i+1))%mod;
//}
//ll c(ll n,ll r) {
	//ll ans = (fact[n] * (in_fact[r] * in_fact[n-r]%mod))%mod;
	//return ans;
//}

signed main(){
    fast;
	//freopen ("input.txt", "r", stdin);
	//freopen ("output.txt", "w", stdout);
    int tt = 1;
    cin>>tt;
    for(int tc = 1; tc <= tt; tc++) {
        int n,f = 0,k = 0;
        cin>>n;
        int ip[n+5];
        //vector<pair<int,int>>finl(mxn);
        map<int,int>finl;
        map<int,int>chk;
        for(int i = 1; i <= n; i++) {
			cin>>ip[i];
			if(chk[ip[i]]) {
				k = 1;
				int dif = i-chk[ip[i]]-1;
				if(dif) {
					f = 1;
					if(finl[ip[i]]) {
						if(finl[ip[i]] > dif) {
							finl[ip[i]] = dif;
						}
					}
					else {
						finl[ip[i]] = dif;
					}
				}
			}
			chk[ip[i]] = i;
		}
		if(k == 1 && f == 0)  {
			cout<<0<<Endl;
			cont;
		}
		if(k == 0) {
			cout<<1<<endl;
			cont;
		}
		int mx = -1, need = -1,ans = 0;
		for(auto it:finl) {
			if(mx < it.second) {
				mx = it.second;
				need = it.first;
			}
		}
		for(int i = 1; i <= n; i++) {
			if(ip[i] == need) {
				if(i) {
					if(ip[i-1] != need) {
						ans++;
					}
				}
			}
		}
		//cout<<need<<endl;
		if(ip[n] != need) ans++;
		cout<<ans<<endl;

    }

return 0;
}


#include<bits/stdc++.h>

using namespace std;

#define int long long
#define ll long long
#define fast ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define endl '\n'
#define Endl '\n'
#define cont continue
#define gcd(a,b) __gcd(a,b)
#define lcm(a,b) a*b/__gcd(a,b)
#define pb push_back
#define mp make_pair
#define mem(x) memset(x, 0, sizeof(x))
#define YES cout<<"YES"<<endl;
#define NO cout<<"NO"<<endl;

const ll inf=1e18;
const int mod=1e9+7;
inline int bigmod(int B,int P){int R=1;while(P>0){if(P&1){R=(R*B)%mod;}P>>=1;B=(B*B)%mod;}return R;}
const int mxn = 2e5+10;

int Mod(int a) {
	if(a < 0)
		return (a+mod)%mod;
	else return a % mod;
}
int Mul(int a, int b) {
	return Mod(Mod(a) * Mod(b));
}
int Add(int a, int b) {
	return Mod(Mod(a) + Mod(b));
}

/*
//sieve starts here
#define svMX            200005
bitset<svMX>siv;
vector<ll>prime;

void sieve () {
    siv[0] = siv[1] = 1; // 0 and 1 are not prime

    prime.push_back(2); // Only Even Prime
    for ( int i = 4; i <= svMX; i += 2 ) siv[i] = 1; // Remove multiples of 2

    int sqrtn = sqrt ( svMX );
    for ( int i = 3; i <= sqrtn; i += 2 ) {
        if ( siv[i] == 0 ) {
            for ( int j = i * i; j <= svMX; j += 2 * i ) siv[j] = 1;
        }
    }

    for ( int i = 3; i <= svMX; i += 2 ) if ( siv[i] == 0 ) prime.push_back(i);
}
//sieve ends here
*/

//ll fact[mxn];
//ll in_fact[mxn];
//fact[0] = 1;
//for(ll i = 1; i < mxn; i++) {
	//fact[i] = (i*fact[i-1])%mod;
//}
//in_fact[mxn-1] = bigmod(fact[mxn-1],mod-2);
//for(ll i = mxn-2; i >= 0; i--) {
	//in_fact[i] = (in_fact[i+1] * (i+1))%mod;
//}
//ll c(ll n,ll r) {
	//ll ans = (fact[n] * (in_fact[r] * in_fact[n-r]%mod))%mod;
	//return ans;
//}

signed main(){
    fast;
	//freopen ("input.txt", "r", stdin);
	//freopen ("output.txt", "w", stdout);
    int tt = 1;
    cin>>tt;
    for(int tc = 1; tc <= tt; tc++) {
        int n,f = 0,k = 0;
        cin>>n;
        int ip[n+5];
        //vector<pair<int,int>>finl(mxn);
        map<int,int>finl;
        map<int,int>chk;
        for(int i = 1; i <= n; i++) {
			cin>>ip[i];
			if(chk[ip[i]]) {
				k = 1;
				int dif = i-chk[ip[i]]-1;
				if(dif) {
					f = 1;
					if(finl[ip[i]]) {
						if(finl[ip[i]] > dif) {
							finl[ip[i]] = dif;
						}
					}
					else {
						finl[ip[i]] = dif;
					}
				}
			}
			chk[ip[i]] = i;
		}
		if(k == 1 && f == 0)  {
			cout<<0<<Endl;
			cont;
		}
		if(k == 0) {
			cout<<1<<endl;
			cont;
		}
		int mx = -1, need = -1,ans = 0;
		for(auto it:finl) {
			if(mx < it.second) {
				mx = it.second;
				need = it.first;
			}
		}
		for(int i = 1; i <= n; i++) {
			if(ip[i] == need) {
				if(i-1) {
					if(ip[i-1] != need) {
						ans++;
					}
				}
			}
		}
		//cout<<need<<endl;
		if(ip[n] != need) ans++;
		cout<<ans<<endl;

    }

return 0;
}


#include<bits/stdc++.h>
#include<vector>
#include<map>
#include<set>
#include<list>
using namespace std;

#define ll signed long long
#define D double
#define LD long double
#define ff first
#define ss second
#define PII pair<int, int>
#define PLL pair<ll,ll>
#define SPLL pair<sll, sll>
#define pb(x) push_back(x)
#define pp() pop_back()
#define in(x) insert(x)
#define vi vector<int>
#define vll vector<ll>
#define vd vector<double>
#define vs vector<string>
#define vc vector<char>
#define vb vector<bool>
#define vpii vector<PII>
#define vvi vector<vi>
#define pn(n) cout<<n<<endl
#define pn2(x,y) cout<<x<<" "<<y<<endl
#define pn3(x, y, z) cout<<x<<' '<<y<<' '<<z<<endl;
#define pr(ar) {for (auto i : ar) cout<<i<<" "; cout<<endl;}
#define get(x) cin>>x;
#define get2(x, y) cin>>x>>y;
#define get3(x, y, z) cin>>x>>y>>z;
#define cn(v) for(auto &i : v) cin>>i;
#define sq(a) (a*a)
#define mpii make_pair
#define eps 1e-9
int dr[] {-1, 0, 1, 0};
int dc[] = {0, 1, 0, -1};

bool many____testttt = 1;
int n, m;

void solve()
{
	int n;
	cin>>n;

	vi v(n);
	cn(v);

	v.erase(unique(v.begin(), v.end()), v.end());
	int best = 1e5;
	vi freq(n+1, 0);
	n = v.size();
	for(int i = 0; i < n; i++) freq[v[i]]++;
	for(int i = 0; i < n; i++)
		best = min(best, freq[v[i]] + 1 - (v.front() == v[i]) - (v.back() == v[i]));
	cout<<best<<endl;

}
void solve_2() {int t; cin>>t; while(t--) solve();}

int main()
{
  if(!many____testttt) solve();
  else solve_2();
  return 0;
}


#include<bits/stdc++.h>
#include<vector>
#include<map>
#include<set>
#include<list>
using namespace std;

#define ll signed long long
#define D double
#define LD long double
#define ff first
#define ss second
#define PII pair<int, int>
#define PLL pair<ll,ll>
#define SPLL pair<sll, sll>
#define pb(x) push_back(x)
#define pp() pop_back()
#define in(x) insert(x)
#define vi vector<int>
#define vll vector<ll>
#define vd vector<double>
#define vs vector<string>
#define vc vector<char>
#define vb vector<bool>
#define vpii vector<PII>
#define vvi vector<vi>
#define pn(n) cout<<n<<endl
#define pn2(x,y) cout<<x<<" "<<y<<endl
#define pn3(x, y, z) cout<<x<<' '<<y<<' '<<z<<endl;
#define pr(ar) {for (auto i : ar) cout<<i<<" "; cout<<endl;}
#define get(x) cin>>x;
#define get2(x, y) cin>>x>>y;
#define get3(x, y, z) cin>>x>>y>>z;
#define cn(v) for(auto &i : v) cin>>i;
#define sq(a) (a*a)
#define mpii make_pair
#define eps 1e-9
int dr[] {-1, 0, 1, 0};
int dc[] = {0, 1, 0, -1};

bool many____testttt = 1;
int n, m;

void solve()
{
	int n;
	cin>>n;
	int mx = 2e5 + 5;
	vi v(mx, 0);
	vi ar(n);
	int x;
	for(int i = 0; i < n; i++){
		cin>>x;
		v[x]++;
		ar[i] = x;
	}

	for(int i = 0; i < n; i++){
		if(v[ar[i]] == n){
			cout<<0<<endl;
			return;
		}
		else if(v[ar[i]] == n - 1){
			cout<<1<<endl;
			return;
		}
	}

	vi nw;
	for(int i = 0; i < n; i++)
	{
		if(nw.size() == 0 || nw.back() != ar[i]) nw.pb(ar[i]);
	}

	vvi pos(mx);
	for(int i = 0; i < nw.size(); i++){
		pos[nw[i]].pb(i);
	}
	int ans = 1000000;
	for(int i = 1; i < mx; i++) if(pos[i].size() > 0) {
		int t = pos[i].size() + 1;
		if(pos[i][0] == 0) t--;
		if(pos[i].size() > 1 && pos[i].back() == nw.size() - 1) t--;
		//pr(pos[i]);
		ans = min(ans, t);
	}
	//pr(nw);
	cout<<ans<<endl;

}
void solve_2() {int t; cin>>t; while(t--) solve();}

int main()
{
  if(!many____testttt) solve();
  else solve_2();
  return 0;
}


#include<bits/stdc++.h>
#include<vector>
#include<map>
#include<set>
#include<list>
using namespace std;

#define ll signed long long
#define D double
#define LD long double
#define ff first
#define ss second
#define PII pair<int, int>
#define PLL pair<ll,ll>
#define SPLL pair<sll, sll>
#define pb(x) push_back(x)
#define pp() pop_back()
#define in(x) insert(x)
#define vi vector<int>
#define vll vector<ll>
#define vd vector<double>
#define vs vector<string>
#define vc vector<char>
#define vb vector<bool>
#define vpii vector<PII>
#define vvi vector<vi>
#define pn(n) cout<<n<<endl
#define pn2(x,y) cout<<x<<" "<<y<<endl
#define pn3(x, y, z) cout<<x<<' '<<y<<' '<<z<<endl;
#define pr(ar) {for (auto i : ar) cout<<i<<" "; cout<<endl;}
#define get(x) cin>>x;
#define get2(x, y) cin>>x>>y;
#define get3(x, y, z) cin>>x>>y>>z;
#define cn(v) for(auto &i : v) cin>>i;
#define sq(a) (a*a)
#define mpii make_pair
#define eps 1e-9
int dr[] {-1, 0, 1, 0};
int dc[] = {0, 1, 0, -1};

bool many____testttt = 1;
int n, m;

void solve()
{
	int n;
	cin>>n;

	vi v(n+1, 0);
	vi ar(n);
	int x;
	for(int i = 0; i < n; i++){
		cin>>x;
		v[x]++;
		ar[i] = x;
	}

	for(int i = 0; i < n; i++){
		if(v[ar[i]] == n){
			cout<<0<<endl;
			return;
		}

	}

	vi nw;
	for(int i = 0; i < n; i++)
	{
		if(nw.size() == 0 || nw.back() != ar[i]) nw.pb(ar[i]);
	}

	vvi pos(n+1);
	for(int i = 0; i < nw.size(); i++){
		pos[nw[i]].pb(i);
	}
	int ans = 1000000;
	for(int i = 1; i <= n; i++) if(pos[i].size() > 0) {
		int t = pos[i].size() + 1;
		if(pos[i][0] == 0) t--;
		if(pos[i].size() > 1 && pos[i].back() == nw.size() - 1) t--;
		if(pos[i][0] != 0 && pos[i].back() == nw.size() - 1) t--;
		//cout<<i<<" ";
		//pr(pos[i]);
		ans = min(ans, t);
	}
	//pr(nw);
	cout<<ans<<endl;

}
void solve_2() {int t; cin>>t; while(t--) solve();}

int main()
{
  if(!many____testttt) solve();
  else solve_2();
  return 0;
}


#include<bits/stdc++.h>
#include<vector>
#include<map>
#include<set>
#include<list>
using namespace std;

#define ll signed long long
#define D double
#define LD long double
#define ff first
#define ss second
#define PII pair<int, int>
#define PLL pair<ll,ll>
#define SPLL pair<sll, sll>
#define pb(x) push_back(x)
#define pp() pop_back()
#define in(x) insert(x)
#define vi vector<int>
#define vll vector<ll>
#define vd vector<double>
#define vs vector<string>
#define vc vector<char>
#define vb vector<bool>
#define vpii vector<PII>
#define vvi vector<vi>
#define pn(n) cout<<n<<endl
#define pn2(x,y) cout<<x<<" "<<y<<endl
#define pn3(x, y, z) cout<<x<<' '<<y<<' '<<z<<endl;
#define pr(ar) {for (auto i : ar) cout<<i<<" "; cout<<endl;}
#define get(x) cin>>x;
#define get2(x, y) cin>>x>>y;
#define get3(x, y, z) cin>>x>>y>>z;
#define cn(v) for(auto &i : v) cin>>i;
#define sq(a) (a*a)
#define mpii make_pair
#define eps 1e-9
int dr[] {-1, 0, 1, 0};
int dc[] = {0, 1, 0, -1};

bool many____testttt = 1;
int n, m;

void solve()
{
	int n;
	cin>>n;

	vi v(n + 1, 0);
	vi ar(n);
	int x;
	for(int i = 0; i < n; i++){
		cin>>x;
		v[x]++;
		ar[i] = x;
	}

	for(int i = 0; i < n; i++){
		if(v[ar[i]] == n){
			cout<<0<<endl;
			return;
		}
		else if(v[ar[i]] == n - 1){
			cout<<1<<endl;
			return;
		}
	}
	vi nw;
	for(int i = 0; i < n; i++)
	{
		if(nw.size() == 0 || nw.back() != ar[i]) nw.pb(ar[i]);
	}
	vvi pos(n+1);
	for(int i = 0; i < nw.size(); i++){
		pos[nw[i]].pb(i);
	}
	int ans = 1000000;
	for(int i = 1; i <= n; i++) if(pos[i].size() != 0) {
		int t = pos[i].size() + 1;
		if(pos[i][0] == 0) t--;
		if(pos[i].size() > 1 && pos[i].back() == pos.size() - 1) t--;
		//pr(pos[i]);
		ans = min(ans, t);
	}
	//pr(nw);
	cout<<ans<<endl;

}
void solve_2() {int t; cin>>t; while(t--) solve();}

int main()
{
  if(!many____testttt) solve();
  else solve_2();
  return 0;
}


#include<bits/stdc++.h>
#include<vector>
#include<map>
#include<set>
#include<list>
using namespace std;

#define ll signed long long
#define D double
#define LD long double
#define ff first
#define ss second
#define PII pair<int, int>
#define PLL pair<ll,ll>
#define SPLL pair<sll, sll>
#define pb(x) push_back(x)
#define pp() pop_back()
#define in(x) insert(x)
#define vi vector<int>
#define vll vector<ll>
#define vd vector<double>
#define vs vector<string>
#define vc vector<char>
#define vb vector<bool>
#define vpii vector<PII>
#define vvi vector<vi>
#define pn(n) cout<<n<<endl
#define pn2(x,y) cout<<x<<" "<<y<<endl
#define pn3(x, y, z) cout<<x<<' '<<y<<' '<<z<<endl;
#define pr(ar) {for (auto i : ar) cout<<i<<" "; cout<<endl;}
#define get(x) cin>>x;
#define get2(x, y) cin>>x>>y;
#define get3(x, y, z) cin>>x>>y>>z;
#define cn(v) for(auto &i : v) cin>>i;
#define sq(a) (a*a)
#define mpii make_pair
#define eps 1e-9
int dr[] {-1, 0, 1, 0};
int dc[] = {0, 1, 0, -1};

bool many____testttt = 1;
int n, m;

void solve()
{
	int n;
	cin>>n;

	vi v(n + 1, 0);
	vi ar(n);
	int x;
	for(int i = 0; i < n; i++){
		cin>>x;
		v[x]++;
		ar[i] = x;
	}

	for(int i = 0; i < n; i++){
		if(v[ar[i]] == n){
			cout<<0<<endl;
			return;
		}
		else if(v[ar[i]] == n - 1){
			cout<<1<<endl;
			return;
		}
	}
	vi nw;
	for(int i = 0; i < n; i++)
	{
		if(nw.size() == 0 || nw.back() != ar[i]) nw.pb(ar[i]);
	}
	vvi pos(n+1);
	for(int i = 0; i < nw.size(); i++){
		pos[nw[i]].pb(i);
	}
	int ans = 1000000;
	int m = pos.size();
	for(int i = 1; i <= n; i++) if(pos[i].size() != 0) {
		int t = pos[i].size() + 1;
		if(pos[i][0] == 0) t--;
		if(pos[i].size() > 1 && pos[i].back() == nw.size() - 1) t--;
		//pr(pos[i]);
		ans = min(ans, t);
	}
	//pr(nw);
	cout<<ans<<endl;

}
void solve_2() {int t; cin>>t; while(t--) solve();}

int main()
{
  if(!many____testttt) solve();
  else solve_2();
  return 0;
}


#include<bits/stdc++.h>
#include<vector>
#include<map>
#include<set>
#include<list>
using namespace std;

#define ll signed long long
#define D double
#define LD long double
#define ff first
#define ss second
#define PII pair<int, int>
#define PLL pair<ll,ll>
#define SPLL pair<sll, sll>
#define pb(x) push_back(x)
#define pp() pop_back()
#define in(x) insert(x)
#define vi vector<int>
#define vll vector<ll>
#define vd vector<double>
#define vs vector<string>
#define vc vector<char>
#define vb vector<bool>
#define vpii vector<PII>
#define vvi vector<vi>
#define pn(n) cout<<n<<endl
#define pn2(x,y) cout<<x<<" "<<y<<endl
#define pn3(x, y, z) cout<<x<<' '<<y<<' '<<z<<endl;
#define pr(ar) {for (auto i : ar) cout<<i<<" "; cout<<endl;}
#define get(x) cin>>x;
#define get2(x, y) cin>>x>>y;
#define get3(x, y, z) cin>>x>>y>>z;
#define cn(v) for(auto &i : v) cin>>i;
#define sq(a) (a*a)
#define mpii make_pair
#define eps 1e-9
int dr[] {-1, 0, 1, 0};
int dc[] = {0, 1, 0, -1};

bool many____testttt = 1;
int n, m;

void solve()
{
	int n;
	cin>>n;
	vi v(n+1, 0);
	vi ar(n);
	int x;
	for(int i = 0; i < n; i++){
		cin>>x;
		v[x]++;
		ar[i] = x;
	}

	for(int i = 0; i < n; i++){
		if(v[ar[i]] == n){
			cout<<0<<endl;
			return;
		}
		else if(v[ar[i]] == n - 1){
			cout<<1<<endl;
			return;
		}
	}

	vi nw;
	for(int i = 0; i < n; i++)
	{
		if(nw.size() == 0 || nw.back() != ar[i]) nw.pb(ar[i]);
	}

	vvi pos(n+1);
	for(int i = 0; i < nw.size(); i++){
		pos[nw[i]].pb(i);
	}
	int ans = 1000000;
	for(int i = 1; i <= n; i++) if(pos[i].size() > 0) {
		int t = pos[i].size() + 1;
		if(pos[i][0] == 0) t--;
		if(pos[i].size() > 1 && pos[i].back() == nw.size() - 1) t--;
		//pr(pos[i]);
		ans = min(ans, t);
	}
	//pr(nw);
	cout<<ans<<endl;

}
void solve_2() {int t; cin>>t; while(t--) solve();}

int main()
{
  if(!many____testttt) solve();
  else solve_2();
  return 0;
}


#include<bits/stdc++.h>
#include<vector>
#include<map>
#include<set>
#include<list>
using namespace std;

#define ll signed long long
#define D double
#define LD long double
#define ff first
#define ss second
#define PII pair<int, int>
#define PLL pair<ll,ll>
#define SPLL pair<sll, sll>
#define pb(x) push_back(x)
#define pp() pop_back()
#define in(x) insert(x)
#define vi vector<int>
#define vll vector<ll>
#define vd vector<double>
#define vs vector<string>
#define vc vector<char>
#define vb vector<bool>
#define vpii vector<PII>
#define vvi vector<vi>
#define pn(n) cout<<n<<endl
#define pn2(x,y) cout<<x<<" "<<y<<endl
#define pn3(x, y, z) cout<<x<<' '<<y<<' '<<z<<endl;
#define pr(ar) {for (auto i : ar) cout<<i<<" "; cout<<endl;}
#define get(x) cin>>x;
#define get2(x, y) cin>>x>>y;
#define get3(x, y, z) cin>>x>>y>>z;
#define cn(v) for(auto &i : v) cin>>i;
#define sq(a) (a*a)
#define mpii make_pair
#define eps 1e-9
int dr[] {-1, 0, 1, 0};
int dc[] = {0, 1, 0, -1};

bool many____testttt = 1;
int n, m;

void solve()
{
	int n;
	cin>>n;
	int mx = 2e5 + 5;
	vi v(mx, 0);
	vi ar(n);
	int x;
	for(int i = 0; i < n; i++){
		cin>>x;
		v[x]++;
		ar[i] = x;
	}

	for(int i = 0; i < n; i++){
		if(v[ar[i]] == n){
			cout<<0<<endl;
			return;
		}
		else if(v[ar[i]] == n - 1){
			cout<<1<<endl;
			return;
		}
	}

	vi nw;
	for(int i = 0; i < n; i++)
	{
		if(nw.size() == 0 || nw.back() != ar[i]) nw.pb(ar[i]);
	}

	vvi pos(n+1);
	for(int i = 0; i < nw.size(); i++){
		pos[nw[i]].pb(i);
	}
	int ans = 1000000;
	for(int i = 1; i <= n; i++) if(pos[i].size() > 0) {
		int t = pos[i].size() + 1;
		if(pos[i][0] == 0) t--;
		if(pos[i].size() > 1 && pos[i].back() == nw.size() - 1) t--;
		//pr(pos[i]);
		ans = min(ans, t);
	}
	//pr(nw);
	cout<<ans<<endl;

}
void solve_2() {int t; cin>>t; while(t--) solve();}

int main()
{
  if(!many____testttt) solve();
  else solve_2();
  return 0;
}


#include<bits/stdc++.h>
#include<vector>
#include<map>
#include<set>
#include<list>
using namespace std;

#define ll signed long long
#define D double
#define LD long double
#define ff first
#define ss second
#define PII pair<int, int>
#define PLL pair<ll,ll>
#define SPLL pair<sll, sll>
#define pb(x) push_back(x)
#define pp() pop_back()
#define in(x) insert(x)
#define vi vector<int>
#define vll vector<ll>
#define vd vector<double>
#define vs vector<string>
#define vc vector<char>
#define vb vector<bool>
#define vpii vector<PII>
#define vvi vector<vi>
#define pn(n) cout<<n<<endl
#define pn2(x,y) cout<<x<<" "<<y<<endl
#define pn3(x, y, z) cout<<x<<' '<<y<<' '<<z<<endl;
#define pr(ar) {for (auto i : ar) cout<<i<<" "; cout<<endl;}
#define get(x) cin>>x;
#define get2(x, y) cin>>x>>y;
#define get3(x, y, z) cin>>x>>y>>z;
#define cn(v) for(auto &i : v) cin>>i;
#define sq(a) (a*a)
#define mpii make_pair
#define eps 1e-9
int dr[] {-1, 0, 1, 0};
int dc[] = {0, 1, 0, -1};

bool many____testttt = 1;
int n, m;

void solve()
{
	int n;
	cin>>n;

	vi v(n);
	cn(v);

	v.erase(unique(v.begin(), v.end()), v.end());
	int best = 1e5;
	vi freq(n+1, 0);
	n = v.size();
	for(int i = 0; i < n; i++) freq[v[i]]++;
	for(int i = 0; i < n; i++)
		best = min(best, freq[v[i]] - (v.front() == i - v.back() == i));

	cout<<best<<endl;

}
void solve_2() {int t; cin>>t; while(t--) solve();}

int main()
{
  if(!many____testttt) solve();
  else solve_2();
  return 0;
}


#include<bits/stdc++.h>
#include<vector>
#include<map>
#include<set>
#include<list>
using namespace std;

#define ll signed long long
#define D double
#define LD long double
#define ff first
#define ss second
#define PII pair<int, int>
#define PLL pair<ll,ll>
#define SPLL pair<sll, sll>
#define pb(x) push_back(x)
#define pp() pop_back()
#define in(x) insert(x)
#define vi vector<int>
#define vll vector<ll>
#define vd vector<double>
#define vs vector<string>
#define vc vector<char>
#define vb vector<bool>
#define vpii vector<PII>
#define vvi vector<vi>
#define pn(n) cout<<n<<endl
#define pn2(x,y) cout<<x<<" "<<y<<endl
#define pn3(x, y, z) cout<<x<<' '<<y<<' '<<z<<endl;
#define pr(ar) {for (auto i : ar) cout<<i<<" "; cout<<endl;}
#define get(x) cin>>x;
#define get2(x, y) cin>>x>>y;
#define get3(x, y, z) cin>>x>>y>>z;
#define cn(v) for(auto &i : v) cin>>i;
#define sq(a) (a*a)
#define mpii make_pair
#define eps 1e-9
int dr[] {-1, 0, 1, 0};
int dc[] = {0, 1, 0, -1};

bool many____testttt = 1;
int n, m;

void solve()
{
	int n;
	cin>>n;

	vi v(n+1, 0);
	vi ar(n);
	int x;
	for(int i = 0; i < n; i++){
		cin>>x;
		v[x]++;
		ar[i] = x;
	}

	for(int i = 0; i < n; i++){
		if(v[ar[i]] == n){
			cout<<0<<endl;
			return;
		}

	}

	vi nw;
	for(int i = 0; i < n; i++)
	{
		if(nw.size() == 0 || nw.back() != ar[i]) nw.pb(ar[i]);
	}

	vvi pos(n+1);
	for(int i = 0; i < nw.size(); i++){
		pos[nw[i]].pb(i);
	}
	int ans = 1000000;
	for(int i = 1; i <= n; i++) if(pos[i].size() > 0) {
		int t = pos[i].size() + 1;
		if(pos[i][0] == 0) t--;
		if(pos[i].size() > 1 && pos[i].back() == nw.size() - 1) t--;
		else if(pos[i][0] != 0 && pos[i].back() == nw.size() - 1) t--;
		//cout<<i<<" ";
		//pr(pos[i]);
		ans = min(ans, t);
	}
	//pr(nw);
	cout<<ans<<endl;

}
void solve_2() {int t; cin>>t; while(t--) solve();}

int main()
{
  if(!many____testttt) solve();
  else solve_2();
  return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define boi	ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define file freopen("input.txt", "r", stdin),freopen("output.txt", "w", stdout)
#define pb push_back
#define F first
#define S second
#define kill(x) return cout<<(x),0;
#define sz(x) ((ll)x.size())
const ll inf=9e18;
const ll mx=1'000'010;
const ll mod=1'000'000'007;
ll n,m,k,a,b,ans,tmp,v,u,w,A[mx],B[mx],C[mx],L,R,id,id2,f,sum,Q,t,p1,p2,par[mx],x,sum2;
double xd,yd;
string s,c,s2,c2;
map<ll,ll>mp;
int main()
{
    boi;
    cin>>Q;
    while(Q--)
    {
        cin>>n;
        ans=inf;
        a=0;
        fill(B,B+n+10,inf);
        for (ll i=0;i<n;++i)
        {
            cin>>A[i];
            if (!i)
                B[A[i]]=1;
            else if (i!=n-1)
            {
                if (A[i]!=A[i-1])
                {
                    if (B[A[i]]==inf)
                        B[A[i]]=2;
                    else
                        ++B[A[i]];
                }
            }
        }
        if (A[n-1]==A[n-2])
            --B[A[n-1]];
        for (ll i=1;i<n;++i)
            if (A[i]!=A[i-1])
                a=1;
        if (!a)
            ans=0;
        for (ll i=1;i<=n;++i)
            ans=min(ans,B[i]);
        cout<<ans<<endl;
    }
    return 0;
}
/*\
\*/


#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define boi	ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define file freopen("input.txt", "r", stdin),freopen("output.txt", "w", stdout)
#define pb push_back
#define F first
#define S second
#define kill(x) return cout<<(x),0;
#define sz(x) ((ll)x.size())
const ll inf=9e18;
const ll mx=1'000'010;
const ll mod=1'000'000'007;
ll n,m,k,a,b,ans,tmp,v,u,w,A[mx],B[mx],C[mx],L,R,id,id2,f,sum,Q,t,p1,p2,par[mx],x,sum2;
double xd,yd;
string s,c,s2,c2;
map<ll,ll>mp;
int main()
{
    boi;
    cin>>Q;
    while(Q--)
    {
        cin>>n;
        ans=inf;
        a=0;
        fill(B,B+n+10,inf);
        for (ll i=0;i<n;++i)
        {
            cin>>A[i];
            if (!i)
                B[A[i]]=1;
            else if (i!=n-1)
            {
                if (A[i]!=A[i-1])
                {
                    if (B[A[i]]==inf)
                        B[A[i]]=2;
                    else
                        ++B[A[i]];
                }
            }
        }
        if (A[n-1]==A[n-2] )//&& A[n-1]!=A[0])
            --B[A[n-1]];
        for (ll i=1;i<n;++i)
            if (A[i]!=A[i-1])
                a=1;
        if (!a)
            ans=0;
        for (ll i=1;i<=n;++i)
        {
            if (B[i])
                ans=min(ans,B[i]);
        }
        cout<<ans<<endl;
    }
    return 0;
}
/*\
\*/


#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define boi	ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define file freopen("input.txt", "r", stdin),freopen("output.txt", "w", stdout)
#define pb push_back
#define F first
#define S second
#define kill(x) return cout<<(x),0;
#define sz(x) ((ll)x.size())
const ll inf=9e18;
const ll mx=1'000'010;
const ll mod=1'000'000'007;
ll n,m,k,a,b,ans,tmp,v,u,w,A[mx],B[mx],C[mx],L,R,id,id2,f,sum,Q,t,p1,p2,par[mx],x,sum2;
double xd,yd;
string s,c,s2,c2;
map<ll,ll>mp;
int main()
{
    boi;
    cin>>Q;
    while(Q--)
    {
        cin>>n;
        ans=inf;
        a=0;
        fill(B,B+n+10,inf);
        for (ll i=0;i<n;++i)
        {
            cin>>A[i];
            if (!i)
                B[A[i]]=1;
            else if (i!=n-1)
            {
                if (A[i]!=A[i-1])
                {
                    if (B[A[i]]==inf)
                        B[A[i]]=2;
                    else
                        ++B[A[i]];
                }

            }
        }
        for (ll i=1;i<n;++i)
            if (A[i]!=A[i-1])
                a=1;
        if (!a)
            ans=0;
        for (ll i=0;i<n;++i)
        {
            if (B[i])
                ans=min(ans,B[i]);
        }
        cout<<ans<<endl;
    }
    return 0;
}
/*\
\*/


#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define boi	ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define file freopen("input.txt", "r", stdin),freopen("output.txt", "w", stdout)
#define pb push_back
#define F first
#define S second
#define kill(x) return cout<<(x),0;
#define sz(x) ((ll)x.size())
const ll inf=9e18;
const ll mx=1'000'010;
const ll mod=1'000'000'007;
ll n,m,k,a,b,ans,tmp,v,u,w,A[mx],B[mx],C[mx],L,R,id,id2,f,sum,Q,t,p1,p2,par[mx],x,sum2;
double xd,yd;
string s,c,s2,c2;
map<ll,ll>mp;
int main()
{
    boi;
    cin>>Q;
    while(Q--)
    {
        cin>>n;
        ans=inf;
        a=0;
        fill(B,B+n+10,inf);
        for (ll i=0;i<n;++i)
        {
            cin>>A[i];
            if (!i)
                B[A[i]]=1;
            else if (i!=n-1)
            {
                if (A[i]!=A[i-1])
                {
                    if (B[A[i]]==inf)
                        B[A[i]]=2;
                    else
                        ++B[A[i]];
                }
            }
        }
        if (A[n-1]==A[n-2] && A[n-1]!=A[0])
            --B[A[n-1]];
        for (ll i=1;i<n;++i)
            if (A[i]!=A[i-1])
                a=1;
        if (!a)
            ans=0;
        for (ll i=1;i<=n;++i)
        {
            if (B[i])
                ans=min(ans,B[i]);
        }
        cout<<ans<<endl;
    }
    return 0;
}
/*\
\*/


#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define boi	ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define file freopen("input.txt", "r", stdin),freopen("output.txt", "w", stdout)
#define pb push_back
#define F first
#define S second
#define kill(x) return cout<<(x),0;
#define sz(x) ((ll)x.size())
const ll inf=9e18;
const ll mx=1'000'010;
const ll mod=1'000'000'007;
ll n,m,k,a,b,ans,tmp,v,u,w,A[mx],B[mx],C[mx],L,R,id,id2,f,sum,Q,t,p1,p2,par[mx],x,sum2;
double xd,yd;
string s,c,s2,c2;
map<ll,ll>mp;
int main()
{
    boi;
    cin>>Q;
    while(Q--)
    {
        cin>>n;
        ans=inf;
        a=0;
        fill(B,B+n+10,0);
        for (ll i=0;i<n;++i)
        {
            cin>>A[i];
            if (!i)
                B[A[i]]=1;
            else
            {
                if (A[i]!=A[i-1])
                    if (!B[A[i]])
                        B[A[i]]=2;
                    else
                        ++B[A[i]];

            }
        }
        if (B[A[n-1]]==2)
            ans=1;
        if (A[0]==A[n-1])
            --B[A[0]];
        for (ll i=1;i<n;++i)
            if (A[i]!=A[i-1])
                a=1;
        if (!a)
            ans=0;
        for (ll i=0;i<n;++i)
        {
            if (B[i])
                ans=min(ans,B[i]);
        }
        cout<<ans<<endl;
    }
    return 0;
}
/*\
\*/


#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define boi	ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define file freopen("input.txt", "r", stdin),freopen("output.txt", "w", stdout)
#define pb push_back
#define F first
#define S second
#define kill(x) return cout<<(x),0;
#define sz(x) ((ll)x.size())
const ll inf=9e18;
const ll mx=1'000'010;
const ll mod=1'000'000'007;
ll n,m,k,a,b,ans,tmp,v,u,w,A[mx],B[mx],C[mx],L,R,id,id2,f,sum,Q,t,p1,p2,par[mx],x,sum2;
double xd,yd;
string s,c,s2,c2;
map<ll,ll>mp;
int main()
{
    boi;
    cin>>Q;
    while(Q--)
    {
        cin>>n;
        ans=inf;
        a=0;
        fill(B,B+n+10,inf);
        for (ll i=0;i<n;++i)
        {
            cin>>A[i];
            if (!i)
                B[A[i]]=1;
            else if (i!=n-1)
            {
                if (A[i]!=A[i-1])
                {
                    if (B[A[i]]==inf)
                        B[A[i]]=2;
                    else
                        ++B[A[i]];
                }
            }
        }
        if (A[n-1]==A[n-2])
            --B[A[n-1]];
        for (ll i=1;i<n;++i)
            if (A[i]!=A[i-1])
                a=1;
        if (!a)
            ans=0;
        for (ll i=1;i<=n;++i)
        {
            if (B[i])
                ans=min(ans,B[i]);
        }
        cout<<ans<<endl;
    }
    return 0;
}
/*\
\*/


#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define boi	ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define file freopen("input.txt", "r", stdin),freopen("output.txt", "w", stdout)
#define pb push_back
#define F first
#define S second
#define kill(x) return cout<<(x),0;
#define sz(x) ((ll)x.size())
const ll inf=9e18;
const ll mx=1'000'010;
const ll mod=1'000'000'007;
ll n,m,k,a,b,ans,tmp,v,u,w,A[mx],B[mx],C[mx],L,R,id,id2,f,sum,Q,t,p1,p2,par[mx],x,sum2;
double xd,yd;
string s,c,s2,c2;
map<ll,ll>mp;
int main()
{
    boi;
    cin>>Q;
    while(Q--)
    {
        cin>>n;
        ans=inf;
        a=0;
        fill(B,B+n+10,inf);
        for (ll i=0;i<n;++i)
        {
            cin>>A[i];
            if (!i)
                B[A[i]]=1;
            else if (i!=n-1)
            {
                if (A[i]!=A[i-1])
                {
                    if (B[A[i]]==inf)
                    {
                        if (i==n-1)
                            B[A[i]]=1;
                        else
                            B[A[i]]=2;
                    }
                    else
                        ++B[A[i]];
                }

            }
        }
        if (B[A[n-1]]==2)
            ans=1;
        if (A[0]==A[n-1])
            --B[A[0]];
        for (ll i=1;i<n;++i)
            if (A[i]!=A[i-1])
                a=1;
        if (!a)
            ans=0;
        for (ll i=0;i<n;++i)
        {
            if (B[i])
                ans=min(ans,B[i]);
        }
        cout<<ans<<endl;
    }
    return 0;
}
/*\
\*/


#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define boi	ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define file freopen("input.txt", "r", stdin),freopen("output.txt", "w", stdout)
#define pb push_back
#define F first
#define S second
#define kill(x) return cout<<(x),0;
#define sz(x) ((ll)x.size())
const ll inf=9e18;
const ll mx=1'000'010;
const ll mod=1'000'000'007;
ll n,m,k,a,b,ans,tmp,v,u,w,A[mx],B[mx],C[mx],L,R,id,id2,f,sum,Q,t,p1,p2,par[mx],x,sum2;
double xd,yd;
string s,c,s2,c2;
map<ll,ll>mp;
int main()
{
    boi;
    cin>>Q;
    while(Q--)
    {
        cin>>n;
        ans=inf;
        a=0;
        fill(B,B+n+10,inf);
        for (ll i=0;i<n;++i)
        {
            cin>>A[i];
            if (!i)
                B[A[i]]=1;
            else if (i!=n-1)
            {
                if (A[i]!=A[i-1])
                {
                    if (B[A[i]]==inf)
                        B[A[i]]=2;
                    else
                        ++B[A[i]];
                }
            }
        }
        if (A[n-1]==A[n-2])
            --B[A[n-1]];
        for (ll i=1;i<n;++i)
            if (A[i]!=A[i-1])
                a=1;
        if (!a)
            ans=0;
        for (ll i=0;i<n;++i)
        {
            if (B[i])
                ans=min(ans,B[i]);
        }
        cout<<ans<<endl;
    }
    return 0;
}
/*\
\*/


#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define boi	ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define file freopen("input.txt", "r", stdin),freopen("output.txt", "w", stdout)
#define pb push_back
#define F first
#define S second
#define kill(x) return cout<<(x),0;
#define sz(x) ((ll)x.size())
const ll inf=9e18;
const ll mx=1'000'010;
const ll mod=1'000'000'007;
ll n,m,k,a,b,ans,tmp,v,u,w,A[mx],B[mx],C[mx],L,R,id,id2,f,sum,Q,t,p1,p2,par[mx],x,sum2;
double xd,yd;
string s,c,s2,c2;
map<ll,ll>mp;
int main()
{
    boi;
    cin>>Q;
    while(Q--)
    {
        cin>>n;
        ans=inf;
        a=0;
        fill(B,B+n+10,inf);
        for (ll i=0;i<n;++i)
        {
            cin>>A[i];
            if (!i)
                B[A[i]]=1;
            else if (i!=n-1)
            {
                if (A[i]!=A[i-1])
                {
                    if (B[A[i]]==inf)
                        B[A[i]]=2;
                    else
                        ++B[A[i]];
                }
            }
        }
        if (B[A[n-1]]==inf)
            ans=1;
        if (A[n-1]==A[n-2])
            --B[A[n-1]];
        for (ll i=1;i<n;++i)
            if (A[i]!=A[i-1])
                a=1;
        if (!a)
            ans=0;
        for (ll i=1;i<=n;++i)
            ans=min(ans,B[i]);
        cout<<ans<<endl;
    }
    return 0;
}
/*\
\*/


#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define boi	ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define file freopen("input.txt", "r", stdin),freopen("output.txt", "w", stdout)
#define pb push_back
#define F first
#define S second
#define kill(x) return cout<<(x),0;
#define sz(x) ((ll)x.size())
const ll inf=9e18;
const ll mx=1'000'010;
const ll mod=1'000'000'007;
ll n,m,k,a,b,ans,tmp,v,u,w,A[mx],B[mx],C[mx],L,R,id,id2,f,sum,Q,t,p1,p2,par[mx],x,sum2;
double xd,yd;
string s,c,s2,c2;
map<ll,ll>mp;
int main()
{
    boi;
    cin>>Q;
    while(Q--)
    {
        cin>>n;
        ans=inf;
        a=0;
        fill(B,B+n+10,inf);
        for (ll i=0;i<n;++i)
        {
            cin>>A[i];
            if (!i)
                B[A[i]]=1;
            else
            {
                if (A[i]!=A[i-1])
                    if (B[A[i]]==inf)
                        B[A[i]]=2;
                    else
                        ++B[A[i]];

            }
        }
        if (B[A[n-1]]==2)
            ans=1;
        if (A[0]==A[n-1])
            --B[A[0]];
        for (ll i=1;i<n;++i)
            if (A[i]!=A[i-1])
                a=1;
        if (!a)
            ans=0;
        for (ll i=0;i<n;++i)
        {
            if (B[i])
                ans=min(ans,B[i]);
        }
        cout<<ans<<endl;
    }
    return 0;
}
/*\
\*/


#include<bits/stdc++.h>
#define X first
#define Y second
#define CLR(x,y) memset(x,y,sizeof(x))
#define ALL(X) X.begin(),X.end()
#define F(i, n) for(int i = 0; i < n; i++)
#define FOR(i, n, m) for(int i = n; i < m; i++)
using namespace std;
typedef pair<int,int> pii;
typedef long long ll;

int a[200005], tmp[200005];
bool used[200005], del[200005];

int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	int t, n;
	cin >> t;
	while (t--){
		CLR(a, 0);
		CLR(used, false);
		CLR(del, false);

		cin >> n;

		cin >> tmp[0];
//		a[tmp[0]]++;
		used[tmp[0]] = true;
		del[0] = true;

		for(int i = 1; i < n-1; i++){
			cin >> tmp[i];
			a[tmp[i]]++;
			used[tmp[i]] = true;
		}

		cin >> tmp[n-1];
//		a[tmp[n-1]]++;
		used[tmp[n-1]] = true;
		del[n-1] = true;

		if(a[tmp[0]] == n-2 && tmp[0] == tmp[n-1]) {
			cout << "0\n";
			continue;
		}

		for(int i = 0; i < n-1; i++){
			if(tmp[i] == tmp[i+1]){
				a[tmp[i]]--;
				del[i+1] = true;
			}
		}

		for(int i = n-1; i > 0; i--){
			if(!del[i] && tmp[i] == tmp[i-1]){
				a[tmp[i]]--;
				del[i] = true;
			}
		}

		int m = 200005;
		for(int i = 1; i <= n; i++){
//			cout << a[i] << ' ' << used[i] << '\t';
			if(!used[i]) continue;
			m = min(m, a[i]);
		}
//		cout << 'f';
		cout << m+1 << '\n';
	}
	return 0;
}


#include<bits/stdc++.h>
#define X first
#define Y second
//#define int long long
#define CLR(x,y) memset(x,y,sizeof(x))
#define ALL(X) X.begin(),X.end()
#define F(i, n) for(int i = 0; i < n; i++)
#define FOR(i, n, m) for(int i = n; i < m; i++)
using namespace std;
typedef pair<int,int> pii;
typedef long long ll;

int a[200005], tmp[200005];
bool used[200005], del[200005];

int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);

	int t, n;
	cin >> t;
	while (t--){
		CLR(a, 0);
		CLR(used, false);
		CLR(del, false);

		cin >> n;

		cin >> tmp[0];
//		a[tmp[0]]++;
		used[tmp[0]] = true;
		del[0] = true;

		for(int i = 1; i < n-1; i++){
			cin >> tmp[i];
			a[tmp[i]]++;
			used[tmp[i]] = true;
		}

		cin >> tmp[n-1];
//		a[tmp[n-1]]++;
		used[tmp[n-1]] = true;
		del[n-1] = true;

		if(a[tmp[0]] == n-2 && tmp[0] == tmp[n-1]) {
			cout << "0\n";
			continue;
		}

		for(int i = 0; i < n-1; i++){
 			if(tmp[i] == tmp[i+1]){
				a[tmp[i]]--;
				del[i+1] = true;
			}
		}

//		for(int i = n-1; i > 0; i--){
//			if(!del[i] && tmp[i] == tmp[i-1]){
//				a[tmp[i]]--;
//				del[i] = true;
//			}
//		}

		int m = 200005;
		for(int i = 1; i <= n; i++){
//			cout << a[i] << ' ' << used[i] << '\t';
			if(!used[i]) continue;
			m = min(m, a[i]);
		}
//		cout << '\n';
		cout << m+1 << '\n';
	}
	return 0;
}


#include<bits/stdc++.h>
#define X first
#define Y second
#define CLR(x,y) memset(x,y,sizeof(x))
#define ALL(X) X.begin(),X.end()
#define F(i, n) for(int i = 0; i < n; i++)
#define FOR(i, n, m) for(int i = n; i < m; i++)
using namespace std;
typedef pair<int,int> pii;
typedef long long ll;

int a[200005], tmp[200005];
bool used[200005];

int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	int t, n;
	cin >> t;
	while (t--){
		CLR(a, 0);
		CLR(used, false);

		cin >> n;

		cin >> tmp[0];
		a[tmp[0]]++;
		used[tmp[0]] = true;

		for(int i = 1; i < n-1; i++){
			cin >> tmp[i];
			a[tmp[i]]++;
			used[tmp[i]] = true;
		}

		cin >> tmp[n-1];
		a[tmp[n-1]]++;
		used[tmp[n-1]] = true;

		if(a[tmp[0]] == n && tmp[0] == tmp[n-1]) {
			cout << "0\n";
			continue;
		}

		for(int i = 0; i < n; i++){
			if(tmp[i] == tmp[0]) a[tmp[0]]--;
			else break;
		}

		for(int i = n-1; i >= 0; i--){
			if(tmp[i] == tmp[n-1]) a[tmp[n-1]]--;
			else break;
		}

		int m = 200005;
		for(int i = 1; i <= n; i++){
//			cout << a[i] << ' ' << used[i] << '\t';
			if(!used[i]) continue;
			m = min(m, a[i]);
		}
//		cout << '\n';
		cout << m+1 << '\n';
	}
	return 0;
}


#include<bits/stdc++.h>
#define X first
#define Y second
#define int long long
#define CLR(x,y) memset(x,y,sizeof(x))
#define ALL(X) X.begin(),X.end()
#define F(i, n) for(int i = 0; i < n; i++)
#define FOR(i, n, m) for(int i = n; i < m; i++)
using namespace std;
typedef pair<int,int> pii;
typedef long long ll;

int a[200005], tmp[200005];
bool used[200005], del[200005];

signed main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	int t, n;
	cin >> t;
	while (t--){
		CLR(a, 0);
		CLR(used, false);
		CLR(del, false);

		cin >> n;

		cin >> tmp[0];
//		a[tmp[0]]++;
		used[tmp[0]] = true;
		del[0] = true;

		for(int i = 1; i < n-1; i++){
			cin >> tmp[i];
			a[tmp[i]]++;
			used[tmp[i]] = true;
		}

		cin >> tmp[n-1];
//		a[tmp[n-1]]++;
		used[tmp[n-1]] = true;
		del[n-1] = true;

		if(a[tmp[0]] == n-2 && tmp[0] == tmp[n-1]) {
			cout << "0\n";
			continue;
		}

		for(int i = 0; i < n-1; i++){
 			if(tmp[i] == tmp[i+1]){
				a[tmp[i]]--;
				del[i+1] = true;
			}
		}

//		for(int i = n-1; i > 0; i--){
//			if(!del[i] && tmp[i] == tmp[i-1]){
//				a[tmp[i]]--;
//				del[i] = true;
//			}
//		}

		int m = 200005;
		for(int i = 1; i <= n; i++){
//			cout << a[i] << ' ' << used[i] << '\t';
			if(!used[i]) continue;
			m = min(m, a[i]);
		}
//		cout << '\n';
		cout << m+1 << '\n';
	}
	return 0;
}


#include<bits/stdc++.h>
#define X first
#define Y second
//#define int long long
#define CLR(x,y) memset(x,y,sizeof(x))
#define ALL(X) X.begin(),X.end()
#define F(i, n) for(int i = 0; i < n; i++)
#define FOR(i, n, m) for(int i = n; i < m; i++)
using namespace std;
typedef pair<int,int> pii;
typedef long long ll;

int a[200005], tmp[200005];
bool used[200005], del[200005];

int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);

	int t, n;
	cin >> t;
	while (t--){
		CLR(a, 0);
		CLR(tmp, 0);
		CLR(used, false);
		CLR(del, false);

		cin >> n;

		cin >> tmp[0];
//		a[tmp[0]]++;
		used[tmp[0]] = true;
		del[0] = true;

		for(int i = 1; i < n-1; i++){
			cin >> tmp[i];
			a[tmp[i]]++;
			used[tmp[i]] = true;
		}

		cin >> tmp[n-1];
//		a[tmp[n-1]]++;
		used[tmp[n-1]] = true;
		del[n-1] = true;

		if(a[tmp[0]] == n-2 && tmp[0] == tmp[n-1]) {
			cout << "0\n";
			continue;
		}

		for(int i = 0; i < n-1; i++){
 			if(tmp[i] == tmp[i+1]){
				a[tmp[i]]--;
				del[i+1] = true;
			}
		}

//		for(int i = n-1; i > 0; i--){
//			if(!del[i] && tmp[i] == tmp[i-1]){
//				a[tmp[i]]--;
//				del[i] = true;
//			}
//		}

		int m = 2000005;
		for(int i = 1; i <= n; i++){
//			cout << a[i] << ' ' << used[i] << '\t';
			if(!used[i]) continue;
			m = min(m, a[i]);
		}
//		cout << '\n';
		cout << m+1 << '\n';
	}
	return 0;
}


#include<bits/stdc++.h>
#define X first
#define Y second
#define int long long
#define CLR(x,y) memset(x,y,sizeof(x))
#define ALL(X) X.begin(),X.end()
#define F(i, n) for(int i = 0; i < n; i++)
#define FOR(i, n, m) for(int i = n; i < m; i++)
using namespace std;
typedef pair<int,int> pii;
typedef long long ll;

int a[200005], tmp[200005];
bool used[200005], del[200005];

signed main(){
	ios::sync_with_stdio(0);
	cin.tie(0);

	int t, n;
	cin >> t;
	while (t--){
		CLR(a, 0);
		CLR(used, false);
		CLR(del, false);

		cin >> n;

		cin >> tmp[0];
//		a[tmp[0]]++;
		used[tmp[0]] = true;
		del[0] = true;

		for(int i = 1; i < n-1; i++){
			cin >> tmp[i];
			a[tmp[i]]++;
			used[tmp[i]] = true;
		}

		cin >> tmp[n-1];
//		a[tmp[n-1]]++;
		used[tmp[n-1]] = true;
		del[n-1] = true;

		if(a[tmp[0]] == n-2 && tmp[0] == tmp[n-1]) {
			cout << "0\n";
			continue;
		}

		for(int i = 0; i < n-1; i++){
 			if(tmp[i] == tmp[i+1]){
				a[tmp[i]]--;
				del[i+1] = true;
			}
		}

//		for(int i = n-1; i > 0; i--){
//			if(!del[i] && tmp[i] == tmp[i-1]){
//				a[tmp[i]]--;
//				del[i] = true;
//			}
//		}

		int m = 200005;
		for(int i = 1; i <= n; i++){
//			cout << a[i] << ' ' << used[i] << '\t';
			if(!used[i]) continue;
			m = min(m, a[i]);
		}
//		cout << '\n';
		cout << m+1 << '\n';
	}
	return 0;
}


#include<bits/stdc++.h>
#define X first
#define Y second
//#define int long long
#define CLR(x,y) memset(x,y,sizeof(x))
#define ALL(X) X.begin(),X.end()
#define F(i, n) for(int i = 0; i < n; i++)
#define FOR(i, n, m) for(int i = n; i < m; i++)
using namespace std;
typedef pair<int,int> pii;
typedef long long ll;

int a[200005], tmp[200005];
bool used[200005], del[200005];

int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);

	int t, n;
	cin >> t;
	while (t--){
		CLR(a, 0);
//		CLR(tmp, 0);
		CLR(used, false);
		CLR(del, false);

		cin >> n;

		cin >> tmp[0];
//		a[tmp[0]]++;
		used[tmp[0]] = true;
		del[0] = true;

		for(int i = 1; i < n-1; i++){
			cin >> tmp[i];
			a[tmp[i]]++;
			used[tmp[i]] = true;
		}

		if(n == 1) {
			cout << "0\n";
			continue;
		}

		cin >> tmp[n-1];
//		a[tmp[n-1]]++;
		used[tmp[n-1]] = true;
		del[n-1] = true;

		if(a[tmp[0]] == n-2 && tmp[0] == tmp[n-1]) {
			cout << "0\n";
			continue;
		}

		for(int i = 0; i < n-1; i++){
 			if(tmp[i] == tmp[i+1]){
				a[tmp[i]]--;
				del[i+1] = true;
			}
		}

//		for(int i = n-1; i > 0; i--){
//			if(!del[i] && tmp[i] == tmp[i-1]){
//				a[tmp[i]]--;
//				del[i] = true;
//			}
//		}

		int m = 2000005;
		for(int i = 1; i <= n; i++){
//			cout << a[i] << ' ' << used[i] << '\t';
			if(!used[i]) continue;
			m = min(m, a[i]);
		}
//		cout << '\n';
		cout << m+1 << '\n';
	}
	return 0;
}


#include<bits/stdc++.h>
#define X first
#define Y second
//#define int long long
#define CLR(x,y) memset(x,y,sizeof(x))
#define ALL(X) X.begin(),X.end()
#define F(i, n) for(int i = 0; i < n; i++)
#define FOR(i, n, m) for(int i = n; i < m; i++)
using namespace std;
typedef pair<int,int> pii;
typedef long long ll;

int a[200005], tmp[200005];
bool used[200005], del[200005];

int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);

	int t, n;
	cin >> t;
	while (t--){
		CLR(a, 0);
//		CLR(tmp, 0);
		CLR(used, false);
		CLR(del, false);

		cin >> n;

		cin >> tmp[0];
//		a[tmp[0]]++;
		used[tmp[0]] = true;
		del[0] = true;

		for(int i = 1; i < n-1; i++){
			cin >> tmp[i];
			a[tmp[i]]++;
			used[tmp[i]] = true;
		}

		cin >> tmp[n-1];
//		a[tmp[n-1]]++;
		used[tmp[n-1]] = true;
		del[n-1] = true;

		if(a[tmp[0]] == n-2 && tmp[0] == tmp[n-1]) {
			cout << "0\n";
			continue;
		}

		for(int i = 0; i < n-1; i++){
 			if(tmp[i] == tmp[i+1]){
				a[tmp[i]]--;
				del[i+1] = true;
			}
		}

//		for(int i = n-1; i > 0; i--){
//			if(!del[i] && tmp[i] == tmp[i-1]){
//				a[tmp[i]]--;
//				del[i] = true;
//			}
//		}

		int m = 2000005;
		for(int i = 1; i <= n; i++){
//			cout << a[i] << ' ' << used[i] << '\t';
			if(!used[i]) continue;
			m = min(m, a[i]);
		}
//		cout << '\n';
		cout << m+1 << '\n';
	}
	return 0;
}


#include<bits/stdc++.h>
#define X first
#define Y second
#define CLR(x,y) memset(x,y,sizeof(x))
#define ALL(X) X.begin(),X.end()
#define F(i, n) for(int i = 0; i < n; i++)
#define FOR(i, n, m) for(int i = n; i < m; i++)
using namespace std;
typedef pair<int,int> pii;
typedef long long ll;

int a[200005], tmp[200005];
bool used[200005], del[200005];

int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	int t, n;
	cin >> t;
	while (t--){
		CLR(a, 0);
		CLR(used, false);
		CLR(del, false);

		cin >> n;

		cin >> tmp[0];
//		a[tmp[0]]++;
		used[tmp[0]] = true;
		del[0] = true;

		for(int i = 1; i < n-1; i++){
			cin >> tmp[i];
			a[tmp[i]]++;
			used[tmp[i]] = true;
		}

		cin >> tmp[n-1];
//		a[tmp[n-1]]++;
		used[tmp[n-1]] = true;
		del[n-1] = true;

		if(a[tmp[0]] == n-2 && tmp[0] == tmp[n-1]) {
			cout << "0\n";
			continue;
		}

		for(int i = 0; i < n-1; i++){
			if(tmp[i] == tmp[i+1]){
				a[tmp[i]]--;
				del[i+1] = true;
			}
		}

//		for(int i = n-1; i > 0; i--){
//			if(!del[i] && tmp[i] == tmp[i-1]){
//				a[tmp[i]]--;
//				del[i] = true;
//			}
//		}

		int m = 200005;
		for(int i = 1; i <= n; i++){
//			cout << a[i] << ' ' << used[i] << '\t';
			if(!used[i]) continue;
			m = min(m, a[i]);
		}
//		cout << '\n';
		cout << m+1 << '\n';
	}
	return 0;
}


#include<bits/stdc++.h>
#define X first
#define Y second
//#define int long long
#define CLR(x,y) memset(x,y,sizeof(x))
#define ALL(X) X.begin(),X.end()
#define F(i, n) for(int i = 0; i < n; i++)
#define FOR(i, n, m) for(int i = n; i < m; i++)
using namespace std;
typedef pair<int,int> pii;
typedef long long ll;

int a[200005], tmp[200005];
bool used[200005], del[200005];

int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);

	ll t, n;
	cin >> t;
	while (t--){
		CLR(a, 0);
		CLR(tmp, 0);
		CLR(used, false);
		CLR(del, false);

		cin >> n;

		cin >> tmp[0];
//		a[tmp[0]]++;
		used[tmp[0]] = true;
		del[0] = true;

		for(int i = 1; i < n-1; i++){
			cin >> tmp[i];
			a[tmp[i]]++;
			used[tmp[i]] = true;
		}

		cin >> tmp[n-1];
//		a[tmp[n-1]]++;
		used[tmp[n-1]] = true;
		del[n-1] = true;

		if(a[tmp[0]] == n-2 && tmp[0] == tmp[n-1]) {
			cout << "0\n";
			continue;
		}

		for(int i = 0; i < n-1; i++){
 			if(tmp[i] == tmp[i+1]){
				a[tmp[i]]--;
				del[i+1] = true;
			}
		}

//		for(int i = n-1; i > 0; i--){
//			if(!del[i] && tmp[i] == tmp[i-1]){
//				a[tmp[i]]--;
//				del[i] = true;
//			}
//		}

		int m = 2000005;
		for(int i = 1; i <= n; i++){
//			cout << a[i] << ' ' << used[i] << '\t';
			if(!used[i]) continue;
			m = min(m, a[i]);
		}
//		cout << '\n';
		cout << m+1 << '\n';
	}
	return 0;
}


#include <bits/stdc++.h>
#define all(v) v.begin(), v.end()
#define ll long long
#define reado                         \
	;                                 \
	freopen("input.txt", "r", stdin); \
	freopen("output.txt", "w", stdout);
#define bist                 \
	;                        \
	ios::sync_with_stdio(0); \
	cin.tie(0);              \
	cout.tie(0);
#define vi vector<int>
#define vc vector<char>
#define vb vector<bool>
#define beg(it) \
	;           \
	map<int, int>::iterator it = mp.begin();
#define vll vector<ll>
#define vs vector<string>
#define all(v) v.begin(), v.end()
using namespace std;
const double eps = 1e-9;
const ll mod = 1000000007;
int main()
{
	//reado;
	bist;
	int t;
	cin >> t;
	while (t--)
	{
		int n;
		cin >> n;
		vi a;
		int x;
		cin >> x;
		set<int> ma;
		for (int i = 1; i < n; i++)
		{
			int xx;
			cin >> xx;
			if (x != xx)
			{
				a.push_back(x);
				ma.insert(x);
			}
			x = xx;
		}
		a.push_back(x);
		ma.insert(x);
		ll cmin = 1e18;
		int tt = a.size();
		for (auto it = ma.begin(); it != ma.end(); ++it)
		{
			int c = 0;
			for (int j = 0; j < tt; j++)
			{
				if (a[j] == *it)
				{
					c += 2;
					if (j == 0 || j == tt - 1)
						c--;
				}
			}
			if (c < cmin)
				cmin = c;
		}
		cout << cmin << " ";
	}
}


#include <bits/stdc++.h>
#define all(v) v.begin(), v.end()
#define ll long long
#define reado                         \
	;                                 \
	freopen("input.txt", "r", stdin); \
	freopen("output.txt", "w", stdout);
#define bist                 \
	;                        \
	ios::sync_with_stdio(0); \
	cin.tie(0);              \
	cout.tie(0);
#define vi vector<int>
#define vc vector<char>
#define vb vector<bool>
#define beg(it) \
	;           \
	map<int, int>::iterator it = mp.begin();
#define vll vector<ll>
#define vs vector<string>
#define all(v) v.begin(), v.end()
using namespace std;
const double eps = 1e-9;
const ll mod = 1000000007;
int main()
{
	//reado;
	bist;
	int t;

	cin >> t;
	while (t--)
	{
		int n;
		cin >> n;
		vi a(n);
		vi c(n,0);
		set<int> b;
		for (int i = 0; i < n; i++)
		{
			int x;
			cin >> x;
			a[i] = x;
			b.insert(x);
			c[x-1]++;
		}
		ll max = 0;
		for (auto i : c)
			if (i > max)
				max = i;
		ll cmin = 1e18;
		for (auto i = b.begin(); i != b.end(); ++i)
		{
			ll c = 0;
			ll last = -1;
			for (int j = 0; j < n; j++)
			{
				if (a[j] == *i)
				{
					if (last != j-1)
						c++;
					last = j;
				}
			}
			if (last != n-1)
				c++;
			if (c < cmin && last != -1)
				cmin = c;
			if (cmin == n-max)
				break;
		}
		cout << cmin << " ";
	}
}


#include <bits/stdc++.h>
#define all(v) v.begin(), v.end()
#define ll long long
#define reado                         \
	;                                 \
	freopen("input.txt", "r", stdin); \
	freopen("output.txt", "w", stdout);
#define bist                 \
	;                        \
	ios::sync_with_stdio(0); \
	cin.tie(0);              \
	cout.tie(0);
#define vi vector<int>
#define vc vector<char>
#define vb vector<bool>
#define beg(it) \
	;           \
	map<int, int>::iterator it = mp.begin();
#define vll vector<ll>
#define vs vector<string>
#define all(v) v.begin(), v.end()
using namespace std;
const double eps = 1e-9;
const ll mod = 1000000007;
int main()
{
	//reado;
	bist;
	int t;

	cin >> t;
	while (t--)
	{
		int n;
		cin >> n;
		vi a(n);
		set<int> b;
		for (int i = 0; i < n; i++)
		{
			int x;
			cin >> x;
			a[i] = x;
			b.insert(x);
		}
		ll cmin = 1e18;
		for (auto i = b.begin(); i != b.end(); ++i)
		{
			ll c = 0;
			ll last = -1;
			for (int j = 0; j < n; j++)
			{
				if (a[j] == *i)
				{
					if (last != j-1)
						c++;
					last = j;
				}
			}
			if (last != n-1)
				c++;
			if (c < cmin && last != -1)
				cmin = c;
			if (cmin == 1)
				break;
		}
		cout << cmin << " ";
	}
}


#include <bits/stdc++.h>
#define all(v) v.begin(), v.end()
#define ll long long
#define reado                         \
	;                                 \
	freopen("input.txt", "r", stdin); \
	freopen("output.txt", "w", stdout);
#define bist                 \
	;                        \
	ios::sync_with_stdio(0); \
	cin.tie(0);              \
	cout.tie(0);
#define vi vector<int>
#define vc vector<char>
#define vb vector<bool>
#define beg(it) \
	;           \
	map<int, int>::iterator it = mp.begin();
#define vll vector<ll>
#define vs vector<string>
#define all(v) v.begin(), v.end()
using namespace std;
const double eps = 1e-9;
const ll mod = 1000000007;
int main()
{
	//reado;
	bist;
	int t;

	cin >> t;
	while (t--)
	{
		int n;
		cin >> n;
		vi a(n);
		set<int> b;
		for (int i = 0; i < n; i++)
		{
			int x;
			cin >> x;
			a[i] = x;
			b.insert(x);
		}
		ll cmin = 1e18;
		for (auto i = b.begin(); i != b.end(); ++i)
		{
			ll c = 0;
			ll last = -1;
			for (int j = 0; j < n; j++)
			{
				if (a[j] == *i)
				{
					if (last != j-1)
						c++;
					last = j;
				}
			}
			if (last != n-1)
				c++;
			if (c < cmin && last != -1)
				cmin = c;
		}
		cout << cmin << " ";
	}
}


#include <bits/stdc++.h>
#define all(v) v.begin(), v.end()
#define ll long long
#define reado                         \
	;                                 \
	freopen("input.txt", "r", stdin); \
	freopen("output.txt", "w", stdout);
#define bist                 \
	;                        \
	ios::sync_with_stdio(0); \
	cin.tie(0);              \
	cout.tie(0);
#define vi vector<int>
#define vc vector<char>
#define vb vector<bool>
#define beg(it) \
	;           \
	map<int, int>::iterator it = mp.begin();
#define vll vector<ll>
#define vs vector<string>
#define all(v) v.begin(), v.end()
using namespace std;
const double eps = 1e-9;
const ll mod = 1000000007;
int main()
{
	//reado;
	bist;
	int t;

	cin >> t;
	while (t--)
	{
		int n;
		cin >> n;
		vi a(n);
		set<int> b;
		for (int i = 0; i < n; i++)
		{
			int x;
			cin >> x;
			a[i] = x;
			b.insert(x);
		}
		ll cmin = 1e18;
		for (auto i = b.begin(); i != b.end(); ++i)
		{
			ll c = 0;
			ll last = -1;
			for (int j = 0; j < n; j++)
			{
				if (a[j] == *i)
				{
					if (last != j-1)
						c++;
					last = j;
				}
			}
			if (last != n-1)
				c++;
			if (c < cmin && last != -1)
				cmin = c;
			if (cmin == n-b.size())
				break;
		}
		cout << cmin << " ";
	}
}