///Astalavista Code........~CodeSlayer007
#include <bits/stdc++.h>
using namespace std;
#define endl "\n"
#define Br cout<<endl
#define int long long
#define fe first
#define se second
#define double long double
#define all(v) v.begin(),v.end()
#define allr(v) v.rbegin(),v.rend()
#define PT(x) cout << (x) << endl
#define PTT(x) cout << (#x) << " is " << (x) << endl
#define lets_go ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
typedef vector<int> vi;
typedef pair<int, int> ii;
typedef vector<ii> vii;
const int M = 1e9 + 7;
const int N = 2000 + 10;
const int IM = 1e15 + 37;
const double PI = 3.1415926535897932384;
inline void PP(int n) { cout << n << " ";}
void PV(vi v) { for (int i = 0 ; i < v.size() ; i++) cout << v[i] << " " ; cout << endl;}
void PVV(vii v) {for (int i = 0 ; i < v.size() ; i++) cout << v[i].first << " " << v[i].second << endl;}
void PA(int v[], int n, int x = 0) { for (int i = x ; i < n + x; i++)cout << v[i] << ' ' ; cout << endl;}
void IN(int a[], int n, int x = 0) {for (int i = x; i < n + x; i++)cin >> a[i];}
inline void op() {
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
}
// <=================================================================================================================================
// <=================================================================================================================================

signed  main() {
    op();
    lets_go

    bitset<10> a, b(1023);
    int n;
    cin >> n;
    //int ok;
    //cin >> ok;
    for (int i = 0; i < n; i++) {
        char c;
        int x;
        cin >> c >> x;
        bitset<10> d(x);
        if (c == '|') {
            a = a | d;
            b = b | d;
            //ok = ok | x;
        }
        else if (c == '&') {
            a = a & d;
            b = b & d;
            //ok = ok & x;
        }
        else {
            a = a ^ d;
            b = b ^ d;
           // ok = ok ^ x;
        }
    }
    int x = 0, y = 0, u = 1, z = 0;
    for (int i = 0; i < 10; i++) {
        if (a[i] == 0 && b[i] == 1)
            continue ;
        else if (a[i] && b[i])
            x = x | u;
        else if (a[i] == 1 && b[i] == 0) {
            z = z | u;
        }
        u = u * 2;
    }
    u = 1;
    for(int i = 0; i < 10; i++){
        if(a[i] == 0 && b[i] == 0)
            continue ;
        y = y | u;
    }
    int zz = (0 ^ z);
    cout << 4 << endl;
    cout << "^ " << z << endl;
    cout << "^ " << zz << endl;
    cout << "& " << y << endl;
    cout << "| " << x << endl;

    /*int ck;
    cin >> ck; PV({x, y, z, zz});
    ck = ck ^ z;
    ck = ck ^ zz;
    ck = ck & y;
    ck = ck | x;

    cout << ck << "---" << ok << endl;*/

    /**/
    return 0;
}


///Astalavista Code........~CodeSlayer007
#include <bits/stdc++.h>
using namespace std;
#define endl "\n"
#define Br cout<<endl
#define int long long
#define fe first
#define se second
#define double long double
#define all(v) v.begin(),v.end()
#define allr(v) v.rbegin(),v.rend()
#define PT(x) cout << (x) << endl
#define PTT(x) cout << (#x) << " is " << (x) << endl
#define lets_go ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
typedef vector<int> vi;
typedef pair<int, int> ii;
typedef vector<ii> vii;
const int M = 1e9 + 7;
const int N = 2000 + 10;
const int IM = 1e15 + 37;
const double PI = 3.1415926535897932384;
inline void PP(int n) { cout << n << " ";}
void PV(vi v) { for (int i = 0 ; i < v.size() ; i++) cout << v[i] << " " ; cout << endl;}
void PVV(vii v) {for (int i = 0 ; i < v.size() ; i++) cout << v[i].first << " " << v[i].second << endl;}
void PA(int v[], int n, int x = 0) { for (int i = x ; i < n + x; i++)cout << v[i] << ' ' ; cout << endl;}
void IN(int a[], int n, int x = 0) {for (int i = x; i < n + x; i++)cin >> a[i];}
inline void op() {
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
}
// <=================================================================================================================================
// <=================================================================================================================================

signed  main() {
    op();
    lets_go

    bitset<10> a, b(1023);
    int n;
    cin >> n;
    //int ok;
    //cin >> ok;
    for (int i = 0; i < n; i++) {
        char c;
        int x;
        cin >> c >> x;
        bitset<10> d(x);
        if (c == '|') {
            a = a | d;
            b = b | d;
            //ok = ok | x;
        }
        else if (c == '&') {
            a = a & d;
            b = b & d;
            //ok = ok & x;
        }
        else {
            a = a ^ d;
            b = b ^ d;
           // ok = ok ^ x;
        }
    }
    int x = 0, y = 0, u = 1, z = 0;
    for (int i = 0; i < 10; i++) {
        if (a[i] == 0 && b[i] == 1)
            continue ;
        else if (a[i] && b[i])
            x = x | u;
        else if (a[i] == 1 && b[i] == 0) {
            z = z | u;
        }
        u = u * 2;
    }
    u = 1;
    for(int i = 0; i < 10; i++){
        if(a[i] == 0 && b[i] == 0){
            u = u * 2;
            continue ;
        }
        y = y | u;
        u = u * 2;
    }
    int zz = (0 ^ z);
    cout << 4 << endl;
    cout << "^ " << z << endl;
    cout << "^ " << zz << endl;
    cout << "& " << y << endl;
    cout << "| " << x << endl;

    /*int ck;
    cin >> ck; PV({x, y, z, zz});
    ck = ck ^ z;
    ck = ck ^ zz;
    ck = ck & y;
    ck = ck | x;

    cout << ck << "---" << ok << endl;*/

    /**/
    return 0;
}


///Astalavista Code........~CodeSlayer007
#include <bits/stdc++.h>
using namespace std;
#define endl "\n"
#define Br cout<<endl
#define int long long
#define fe first
#define se second
#define double long double
#define all(v) v.begin(),v.end()
#define allr(v) v.rbegin(),v.rend()
#define PT(x) cout << (x) << endl
#define PTT(x) cout << (#x) << " is " << (x) << endl
#define lets_go ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
typedef vector<int> vi;
typedef pair<int, int> ii;
typedef vector<ii> vii;
const int M = 1e9 + 7;
const int N = 2000 + 10;
const int IM = 1e15 + 37;
const double PI = 3.1415926535897932384;
inline void PP(int n) { cout << n << " ";}
void PV(vi v) { for (int i = 0 ; i < v.size() ; i++) cout << v[i] << " " ; cout << endl;}
void PVV(vii v) {for (int i = 0 ; i < v.size() ; i++) cout << v[i].first << " " << v[i].second << endl;}
void PA(int v[], int n, int x = 0) { for (int i = x ; i < n + x; i++)cout << v[i] << ' ' ; cout << endl;}
void IN(int a[], int n, int x = 0) {for (int i = x; i < n + x; i++)cin >> a[i];}
inline void op() {
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
}
// <=================================================================================================================================
// <=================================================================================================================================

signed  main() {
    op();
    lets_go

    bitset<10> a, b(1023);
    int n;
    cin >> n;
    int ok = 1;
    //cin >> ok;
    for (int i = 0; i < n; i++) {
        char c;
        int x;
        cin >> c >> x;
        bitset<10> d(x);
        if (c == '|') {
            a = a | d;
            b = b | d;
            ok = ok | x;
        }
        else if (c == '&') {
            a = a & d;
            b = b & d;
            ok = ok & x;
        }
        else {
            a = a ^ d;
            b = b ^ d;
            ok = ok ^ x;
        }
    }
    int x = 0, y = 0, u = 1, z = 0,zz = 1023;
    for (int i = 0; i < 10; i++) {
        if (a[i] == 0 && b[i] == 1){
            u = u * 2;
            continue ;
        }
        else if (a[i] && b[i])
            x = x | u;
        else if (a[i] == 1 && b[i] == 0) {
            z = z | u;
        }
        u = u * 2;
    }
    u = 1;
    for(int i = 0; i < 10; i++){
        if(a[i] == 0 && b[i] == 0){
            u = u * 2;
            continue ;
        }
        y = y | u;
        u = u * 2;
    }
    zz = 0;
    //int zz = (0 ^ z);
    cout << 4 << endl;
    cout << "^ " << z << endl;
    cout << "^ " << zz << endl;
    cout << "& " << y << endl;
    cout << "| " << x << endl;

   /* int ck;
    cin >> ck; PV({x, y, z, zz});
    ck = ck ^ z;
    ck = ck ^ zz;
    ck = ck & y;
    ck = ck | x;

    cout << ck << "---" << ok << endl;*/

    /**/
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long LL;

#ifdef BTK
#define DEBUG if(1)
#else
#define DEBUG if(0)
#define CIN_ONLY if(0)
struct cww{cww(){
    CIN_ONLY{
        ios::sync_with_stdio(false);cin.tie(0);
    }
}}star;
#endif

#define FOR(i,bg,ed) for(int i=(bg);i<(ed);i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
#define fi first
#define se second
#define pb push_back
#define REC(ret, ...) std::function<ret (__VA_ARGS__)>
template <typename T>inline bool chmin(T &l,T r){bool a=l>r;if(a)l=r;return a;}
template <typename T>inline bool chmax(T &l,T r){bool a=l<r;if(a)l=r;return a;}
template <typename T>istream& operator>>(istream &is,vector<T> &v){for(auto &it:v)is>>it;return is;}

constexpr char ln = '\n';
constexpr int mod = 1e9+7;
const string ok = "Yes";
const string ng = "No";

#define POS(x,i) ((x>>i)&1)

int main(){
    int n;
    scanf("%d",&n);
    int x0=0;
    int x1=1023;
    /*
    vector<int> a(1024);
    REP(i,1024)a[i]=i;
    auto b=a;
    */
    REP(i,n){
        char s[2];
        int p;
        scanf("%s%d",s,&p);
        if(s[0]=='|'){
            x0|=p;
            x1|=p;
            //REP(j,1024)a[j]|=p;
        }
        else if(s[0]=='&'){
            x0&=p;
            x1&=p;
            //REP(j,1024)a[j]&=p;
        }
        else{
            x0^=p;
            x1^=p;
            //REP(j,1024)a[j]^=p;
        }
    }
    int y0=0,y1=0,y2=0;
    REP(i,10){
        if(POS(x0,i)==1&&POS(x1,i)==1)y0|=(1<<i);
        if(POS(x0,i)==0&&POS(x1,i)==0)y1|=(1<<i);
        if(POS(x0,i)==1&&POS(x1,i)==0)y2|=(1<<i);
    }
    y1=1023-y1;
    /*
    REP(i,1024){
        b[i]|=y0;
        b[i]&=y1;
        b[i]^=y2;
        if(a[i]!=b[i])cout<<i<<a[i]<<b[i]<<endl;
    }
    */
    printf("3 \n");fflush(stdout);
    printf("| %d\n",y0);fflush(stdout);
    printf("& %d\n",y1);fflush(stdout);
    printf("^ %d\n",y2);fflush(stdout);

    return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long LL;

#ifdef BTK
#define DEBUG if(1)
#else
#define DEBUG if(0)
#define CIN_ONLY if(1)
struct cww{cww(){
    CIN_ONLY{
        ios::sync_with_stdio(false);cin.tie(0);
    }
}}star;
#endif

#define FOR(i,bg,ed) for(int i=(bg);i<(ed);i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
#define fi first
#define se second
#define pb push_back
#define REC(ret, ...) std::function<ret (__VA_ARGS__)>
template <typename T>inline bool chmin(T &l,T r){bool a=l>r;if(a)l=r;return a;}
template <typename T>inline bool chmax(T &l,T r){bool a=l<r;if(a)l=r;return a;}
template <typename T>istream& operator>>(istream &is,vector<T> &v){for(auto &it:v)is>>it;return is;}

constexpr char ln = '\n';
constexpr int mod = 1e9+7;
const string ok = "Yes";
const string ng = "No";

#define POS(x,i) ((x>>i)&1)

int main(){
    int n;
    cin>>n;
    int x0=0;
    int x1=1023;
    REP(i,n){
        string s;
        int p;
        cin>>s>>p;
        if(s[0]=='|'){
            x0|=p;
            x1|=p;
        }
        else if(s[0]=='&'){
            x0&=p;
            x1&=p;
        }
        else{
            x0^=p;
            x1^=p;
        }
    }
    int y0=0,y1=0,y2=0;
    REP(i,10){
        if(POS(x0,i)==1&&POS(x1,i)==1)y0|=(1<<i);
        if(POS(x0,i)==0&&POS(x1,i)==0)y1|=(1<<i);
        if(POS(x0,i)==1&&POS(x1,i)==0)y2|=(1<<i);
    }
    y1=1023-y1;
    cout<<3<<endl;
    cout<<"| "<<y0<<endl;
    cout<<"& "<<y1<<endl;
    cout<<"^ "<<y2<<endl;

    return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long LL;

#ifdef BTK
#define DEBUG if(1)
#else
#define DEBUG if(0)
#define CIN_ONLY if(1)
struct cww{cww(){
    CIN_ONLY{
        ios::sync_with_stdio(false);cin.tie(0);
    }
}}star;
#endif

#define FOR(i,bg,ed) for(int i=(bg);i<(ed);i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
#define fi first
#define se second
#define pb push_back
#define REC(ret, ...) std::function<ret (__VA_ARGS__)>
template <typename T>inline bool chmin(T &l,T r){bool a=l>r;if(a)l=r;return a;}
template <typename T>inline bool chmax(T &l,T r){bool a=l<r;if(a)l=r;return a;}
template <typename T>istream& operator>>(istream &is,vector<T> &v){for(auto &it:v)is>>it;return is;}

constexpr char ln = '\n';
constexpr int mod = 1e9+7;
const string ok = "Yes";
const string ng = "No";

#define POS(x,i) ((x>>i)&1)

int main(){

    int n;
    scanf("%d",&n);
    int x0=0;
    int x1=1023;
    REP(i,n){
        char s[2];
        int p;
        scanf("%s%d",s,&p);
        if(s[0]=='|'){
            x0|=p;
            x1|=p;
        }
        else if(s[0]=='&'){
            x0&=p;
            x1&=p;
        }
        else{
            x0^=p;
            x1^=p;
        }
    }
    int y0=0,y1=0,y2=0;
    REP(i,10){
        if(POS(x0,i)==1&&POS(x1,i)==1)y0|=(1<<i);
        if(POS(x0,i)==0&&POS(x1,i)==0)y1|=(1<<i);
        if(POS(x0,i)==1&&POS(x1,i)==0)y2|=(1<<i);
    }
    y1=1023-y1;
    printf("3 \n");
    printf("| %d\n",y0);
    printf("& %d\n",y1);
    printf("^ %d\n",y2);

    return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long LL;

#ifdef BTK
#define DEBUG if(1)
#else
#define DEBUG if(0)
#define CIN_ONLY if(1)
struct cww{cww(){
    CIN_ONLY{
        ios::sync_with_stdio(false);cin.tie(0);
    }
}}star;
#endif

#define FOR(i,bg,ed) for(int i=(bg);i<(ed);i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
#define fi first
#define se second
#define pb push_back
#define REC(ret, ...) std::function<ret (__VA_ARGS__)>
template <typename T>inline bool chmin(T &l,T r){bool a=l>r;if(a)l=r;return a;}
template <typename T>inline bool chmax(T &l,T r){bool a=l<r;if(a)l=r;return a;}
template <typename T>istream& operator>>(istream &is,vector<T> &v){for(auto &it:v)is>>it;return is;}

constexpr char ln = '\n';
constexpr int mod = 1e9+7;
const string ok = "Yes";
const string ng = "No";

#define POS(x,i) ((x>>i)&1)

int main(){
    int n;
    scanf("%d",&n);
    int x0=0;
    int x1=1023;
    /*
    vector<int> a(1024);
    REP(i,1024)a[i]=i;
    auto b=a;
    */
    REP(i,n){
        char s[2];
        int p;
        scanf("%s%d",s,&p);
        if(s[0]=='|'){
            x0|=p;
            x1|=p;
            //REP(j,1024)a[j]|=p;
        }
        else if(s[0]=='&'){
            x0&=p;
            x1&=p;
            //REP(j,1024)a[j]&=p;
        }
        else{
            x0^=p;
            x1^=p;
            //REP(j,1024)a[j]^=p;
        }
    }
    int y0=0,y1=0,y2=0;
    REP(i,10){
        if(POS(x0,i)==1&&POS(x1,i)==1)y0|=(1<<i);
        if(POS(x0,i)==0&&POS(x1,i)==0)y1|=(1<<i);
        if(POS(x0,i)==1&&POS(x1,i)==0)y2|=(1<<i);
    }
    y1=1023-y1;
    /*
    REP(i,1024){
        b[i]|=y0;
        b[i]&=y1;
        b[i]^=y2;
        if(a[i]!=b[i])cout<<i<<a[i]<<b[i]<<endl;
    }
    */
    printf("3 \n");fflush(stdout);
    printf("| %d\n",y0);fflush(stdout);
    printf("& %d\n",y1);fflush(stdout);
    printf("^ %d\n",y2);fflush(stdout);

    return 0;
}


#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

const int N = 5e5 + 100;

char q[N];
int x[N];

inline bool bit (int mask, int pos) {
	return (mask >> pos) & 1;
}

int main () {

	#ifdef LOCAL
	freopen ("in", "r", stdin);
	#endif

	ios_base :: sync_with_stdio (0);
	cin.tie (0);

	int n;
	cin >> n;

	int op[3];
	//0 - or, 1 - and, 2 - xor
	op[0] = op[1] = op[2] = 0;

	for (int i = 1; i <= n; ++i) {
		cin >> q[i] >> x[i];
	}

	for (int k = 0; k < 10; ++k) {
		int state = 2;
		for (int i = 1; i <= n; ++i) {
			if (q[i] == '|') {
				if (bit (x[i], k)) {
					state = 1;
				}
			}
			if (q[i] == '&') {
				if (!bit (x[i], k)) {
					state = 0;
				}
			}
			if (q[i] == '^') {
				state ^= 1;
			}
		}
		if (state == 0) {

		}
		if (state == 1) {
			op[0] |= (1 << k);
			op[1] |= (1 << k);
		}
		if (state == 2) {
			op[1] |= (1 << k);
		}
		if (state == 3) {
			op[1] |= (1 << k);
			op[2] |= (1 << k);
		}
	}

	cout << 3 << "\n" << "| " << op[0] << "\n" << "& " << op[1] << "\n" << "^ " << op[2] << "\n";

	return 0;
}


#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

const int N = 5e5 + 100;

char q[N];
int x[N];

inline bool bit (int mask, int pos) {
	return (mask >> pos) & 1;
}

int main () {

	#ifdef LOCAL
	freopen ("in", "r", stdin);
	#endif

	ios_base :: sync_with_stdio (0);
	cin.tie (0);

	int n;
	cin >> n;

	int op[3];
	//0 - or, 1 - and, 2 - xor
	op[0] = op[1] = op[2] = 0;

	for (int i = 1; i <= n; ++i) {
		cin >> q[i] >> x[i];
	}

	for (int k = 0; k < 10; ++k) {
		int state = 2;
		for (int i = 1; i <= n; ++i) {
			if (q[i] == '|') {
				if (bit (x[i], k))
					state = 1;
			}
			if (q[i] == '&') {
				if (!bit (x[i], k))
					state = 0;
			}
			if (q[i] == '^') {
				if (bit (x[i], k))
					state ^= 1;
			}
		}
		if (state == 0) {

		}
		if (state == 1) {
			op[0] |= (1 << k);
			op[1] |= (1 << k);
		}
		if (state == 2) {
			op[1] |= (1 << k);
		}
		if (state == 3) {
			op[1] |= (1 << k);
			op[2] |= (1 << k);
		}
		cerr << k << " " << state << "\n";
	}

	cout << 3 << "\n" << "| " << op[0] << "\n" << "& " << op[1] << "\n" << "^ " << op[2] << "\n";

	return 0;
}


#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;

#define ll long long int
#define pb push_back
#define endl "\n"
#define F first
#define S second

#define mp map<ll,ll>
#define vc vector<ll>
#define pq priority_queue<pair<ll,ll>,vector<pair<ll,ll>>,greater<pair<ll,ll>>>
#define MAX  *max_element
#define MIN  *min_element
#define lcm(a,b) (a*b)/__gcd(a,b)
#define des_sort(v) sort(v.begin(),v.end(),greater<int>())
//max xor btw range of two numbers..

#define max_XOR(a,b) (1 << int(log2(a ^ b) + 1)) - 1
#define c_ones(number) __builtin_popcountll(number)
#define flip_bits(number) static_cast<unsigned>(~number)

#define all(X) X.begin(),X.end()
#define rep(i,n) for(ll i=0;i<n;i++)
#define loop(itr,n) for(itr=n.begin();itr!=n.end();itr++)

#define FLUSH fflush(stdout)
#define FAST ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define pb_ds tree<pair<int,int>, null_type,less<pair<int,int>>, rb_tree_tag,tree_order_statistics_node_update>
#define mod 1000000007
#define INF 1e18

const double PI = acos(-1);

bool compare(pair<int,int>a , pair<int,int>b){
	return a.first==b.first ? a.second<b.second : a.first < b.first;
}

struct hash_pair{
    template <class T1, class T2>
    size_t operator()(const pair<T1, T2>& p) const
    {
        auto hash1 = hash<T1>{}(p.first);
        auto hash2 = hash<T2>{}(p.second);
        return hash1 ^ hash2;
    }
};

int main(){
	int n;
	cin>>n;
	vector<pair<char,int>> v(n);
	rep(i,n){
		cin>>v[i].first>>v[i].second;
	}
	vector<int> vo,va,vx;
	rep(i,10){
		int x1=1<<i,x2=0;
		rep(j,v.size()){
			char ch = v[i].first;
			int y = v[i].second;
			if(ch=='&'){
				x1 &= y;
				x2 &= y;
			}
			else if(ch=='|'){
				x1 |= y;
				x2 |= y;
			}
			else{
				x1 ^= y;
				x2 ^= y;
			}
		}
		if(x1&(1<<i)){
			if(x2&(1<<i))vo.pb(i);
		}
		else{
			if(x2&(1<<i))vx.pb(i);
			else va.pb(i);
		}
	}
	int ans1=0,ans2=0,ans3=0;
	rep(i,vo.size())ans1 += (1<<i);
	rep(i,vx.size())ans2 += (1<<i);
	rep(i,va.size())ans3 += (1<<i);
	ans3 = ~ans3 & ((1<<10)-1);
	cout<<3<<endl;
	cout<<"| "<<ans1<<endl;
	cout<<"^ "<<ans2<<endl;
	cout<<"& "<<ans3<<endl;
}


#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;

#define ll long long int
#define pb push_back
#define endl "\n"
#define F first
#define S second

#define mp map<ll,ll>
#define vc vector<ll>
#define pq priority_queue<pair<ll,ll>,vector<pair<ll,ll>>,greater<pair<ll,ll>>>
#define MAX  *max_element
#define MIN  *min_element
#define lcm(a,b) (a*b)/__gcd(a,b)
#define des_sort(v) sort(v.begin(),v.end(),greater<int>())
//max xor btw range of two numbers..

#define max_XOR(a,b) (1 << int(log2(a ^ b) + 1)) - 1
#define c_ones(number) __builtin_popcountll(number)
#define flip_bits(number) static_cast<unsigned>(~number)

#define all(X) X.begin(),X.end()
#define rep(i,n) for(ll i=0;i<n;i++)
#define loop(itr,n) for(itr=n.begin();itr!=n.end();itr++)

#define FLUSH fflush(stdout)
#define FAST ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define pb_ds tree<pair<int,int>, null_type,less<pair<int,int>>, rb_tree_tag,tree_order_statistics_node_update>
#define mod 1000000007
#define INF 1e18

const double PI = acos(-1);

bool compare(pair<int,int>a , pair<int,int>b){
	return a.first==b.first ? a.second<b.second : a.first < b.first;
}

struct hash_pair{
    template <class T1, class T2>
    size_t operator()(const pair<T1, T2>& p) const
    {
        auto hash1 = hash<T1>{}(p.first);
        auto hash2 = hash<T2>{}(p.second);
        return hash1 ^ hash2;
    }
};

int main(){
	int n;
	cin>>n;
	vector<pair<char,int>> v(n);
	rep(i,n){
		cin>>v[i].first>>v[i].second;
	}
	vector<int> vo,va,vx;
	rep(i,10){
		int x1=(1<<i),x2=0;
		rep(j,v.size()){
			char ch = v[j].first;
			int y = v[j].second;
			if(ch=='&'){
				x1 &= y;
				x2 &= y;
			}
			else if(ch=='|'){
				x1 |= y;
				x2 |= y;
			}
			else{
				x1 ^= y;
				x2 ^= y;
			}
		}
		if(x1&(1<<i)){
			if(x2&(1<<i))vo.pb(i);
		}
		else{
			if(x2&(1<<i))vx.pb(i);
			else va.pb(i);
		}
	}
	int ans1=0,ans2=0,ans3=0;
	rep(i,vo.size())ans1 += (1<<vo[i]);
	rep(i,vx.size())ans2 += (1<<vx[i]);
	rep(i,va.size())ans3 += (1<<va[i]);
	ans3 = (~ans3 & ((1<<10)-1));
	cout<<3<<endl;
	cout<<"| "<<ans1<<endl;
	cout<<"^ "<<ans2<<endl;
	cout<<"& "<<ans3<<endl;
}


#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;

#define ll long long int
#define pb push_back
#define endl "\n"
#define F first
#define S second

#define mp map<ll,ll>
#define vc vector<ll>
#define pq priority_queue<pair<ll,ll>,vector<pair<ll,ll>>,greater<pair<ll,ll>>>
#define MAX  *max_element
#define MIN  *min_element
#define lcm(a,b) (a*b)/__gcd(a,b)
#define des_sort(v) sort(v.begin(),v.end(),greater<int>())
//max xor btw range of two numbers..

#define max_XOR(a,b) (1 << int(log2(a ^ b) + 1)) - 1
#define c_ones(number) __builtin_popcountll(number)
#define flip_bits(number) static_cast<unsigned>(~number)

#define all(X) X.begin(),X.end()
#define rep(i,n) for(ll i=0;i<n;i++)
#define loop(itr,n) for(itr=n.begin();itr!=n.end();itr++)

#define FLUSH fflush(stdout)
#define FAST ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define pb_ds tree<pair<int,int>, null_type,less<pair<int,int>>, rb_tree_tag,tree_order_statistics_node_update>
#define mod 1000000007
#define INF 1e18

const double PI = acos(-1);

bool compare(pair<int,int>a , pair<int,int>b){
	return a.first==b.first ? a.second<b.second : a.first < b.first;
}

struct hash_pair{
    template <class T1, class T2>
    size_t operator()(const pair<T1, T2>& p) const
    {
        auto hash1 = hash<T1>{}(p.first);
        auto hash2 = hash<T2>{}(p.second);
        return hash1 ^ hash2;
    }
};

int main(){
	int n;
	cin>>n;
	vector<pair<char,int>> v(n);
	rep(i,n){
		cin>>v[i].first>>v[i].second;
	}
	vector<int> vo,va,vx;
	rep(i,10){
		int x1=(1<<i),x2=0;
		rep(j,v.size()){
			char ch = v[j].first;
			int y = v[j].second;
			if(ch=='&'){
				x1 &= y;
				x2 &= y;
			}
			else if(ch=='|'){
				x1 |= y;
				x2 |= y;
			}
			else{
				x1 ^= y;
				x2 ^= y;
			}
		}
		if(x1&(1<<i)){
			if(x2&(1<<i))vo.pb(i);
		}
		else{
			if(x2&(1<<i))vx.pb(i);
			else va.pb(i);
		}
	}
	int ans1=0,ans2=0,ans3=0;
	rep(i,vo.size())ans1 += (1<<i);
	rep(i,vx.size())ans2 += (1<<i);
	rep(i,va.size())ans3 += (1<<i);
	ans3 = ~ans3 & ((1<<10)-1);
	cout<<3<<endl;
	cout<<"| "<<ans1<<endl;
	cout<<"^ "<<ans2<<endl;
	cout<<"& "<<ans3<<endl;
}


#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;

int ans=0;

struct uftree{
	int par[(1<<13)*65];
	int rank[(1<<13)*65];
	uftree(){
	}
	void init(int n){
		for(int i=0;i<n;i++){
			par[i]=i;
			rank[i]=0;
		}
	}
	int find(int x){
		if(par[x]==x)return x;
		return par[x]=find(par[x]);
	}

	void unite(int x,int y){
		x=find(x);
		y=find(y);
		if(x==y)return;
		ans--;
		if(rank[x]<rank[y]){
			par[x]=y;
		}else{
			if(rank[x]==rank[y])rank[x]++;
			par[y]=x;
		}
	}

	bool same(int x,int y){
		return find(x)==find(y);
	}
};

uftree uf;

int n,m;
int len;
int now[65][1<<14];
bool used[65][1<<14];
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};

bool nm[(1<<13)*65];

void bfs(int sy,int sx,int col){
	queue<P> que;
	que.push(P(sy,sx));
	col=uf.find(col);
	now[sy][sx]=col;
	used[sy][sx]=true;
	while(que.size()){
		P p=que.front();
		que.pop();
		for(int i=0;i<4;i++){
			int nx=p.second+dx[i];
			int ny=p.first+dy[i];
			if(nx>=0 && nx<m && ny>=0 && ny<=len){
				if(!used[ny][nx] && now[ny][nx]>=0){
					used[ny][nx]=true;
					if(now[ny][nx]!=-1 && now[ny][nx]!=(10000000)){
						uf.unite(col,now[ny][nx]);
					}
					now[ny][nx]=col;
					que.push(P(ny,nx));
				}
			}
		}
	}
}

char str[(1<<12)+11];

int main(void){
	scanf("%d%d%*c",&n,&m);
	int all=0;
	memset(nm,false,sizeof(nm));
	memset(now,-1,sizeof(now));
	uf.init((1<<13)*65);
	int nown=0;
	for(int i=0;i<(n+63)/64;i++){
		len=min(64,n-nown);
		for(int j=0;j<len;j++){
			scanf("%s",str);
			for(int k=0;k<m/4;k++){
				int v=0;
				if(str[k]>='A' && str[k]<='F'){
					v=10+(str[k]-'A');
				}else{
					v=(str[k]-'0');
				}
				for(int l=3;l>=0;l--){
					if(v>>l & 1){
						now[j+1][k*4+4-l-1]=10000000;
					}else{
						now[j+1][k*4+4-l-1]=-1;
					}
				}
			}
		}
		memset(used,false,sizeof(used));
		for(int j=0;j<m;j++){
			if(!used[0][j] && now[0][j]!=-1){
				bfs(0,j,now[0][j]);
			}
		}
		int nu=0;
		for(int k=0;k<len;k++){
			for(int j=0;j<m;j++){
				if(!used[k+1][j] && now[k+1][j]>=0){
					while(nm[nu])nu++;
					uf.par[nu]=nu;
					uf.rank[nu]=0;
					now[k+1][j]=nu++;
					ans++;
					bfs(k+1,j,now[k+1][j]);
				}
			}
		}
		memset(nm,false,sizeof(nm));
		for(int j=0;j<m;j++){
			if(now[len][j]>=0){
				now[0][j]=uf.find(now[len][j]);
				nm[now[0][j]]=true;
			}else{
				now[0][j]=-1;
			}
		}
		nown+=len;
	}
	printf("%d\n",ans);
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
vector<pair<char,int>>a;
int main() {
	int lines;
	cin>>lines;
	int OR=0,AND=1023,XOR=0;
	while(lines--){
		char c;
		int t;
		cin>>c>>t;
		if(c=='&')AND&=t;
		if(c=='|')OR|=t;
		if(c=='^'){
			AND^=t;
			OR^=t;
			XOR^=t;
		}
	}
	printf("3\n");
	printf("^ %d\n",XOR);
	printf("| %d\n",OR);
	printf("& %d\n",AND);
}


#include<bits/stdc++.h>
using namespace std;
vector<pair<char,int>>a;
int main() {
	int lines,OR=0,AND=1023,XOR=0;
	cin>>lines;
	while(lines--){
		char c;
		int t;
		cin>>c>>t;
		if(c=='&')AND&=t;
		if(c=='|')OR|=t;
		if(c=='^'){
			AND^=t;
			OR^=t;
			XOR^=t;
		}
	}
	printf("3\n");
	printf("^ %d\n",XOR);
	printf("| %d\n",OR);
	printf("& %d\n",AND);
}


#include <bits/stdc++.h>
using namespace std;
#define en '\n'
#define ll long int
#define BFL(i, a, b) for (i = a; i < b; i++)
void vec_i(string str, vector<int> &v)
{
  int a;
  istringstream stream(str);
  while (stream >> a)
    v.push_back(a);
}
int main()
{

  // ifstream cin("input.txt");
  // ofstream cout("output.txt");
  ll t;
  cin >> t;
  while (t--)
  {

    ll i, n, a[int(1 * 1e5)];
    cin >> n;

    ll p[int(1 * 1e5)] = {0}, ans = n;
    BFL(i, 0, n)
    cin >> a[i];

    // no of times a number occurs

    BFL(i, 0, n)
    if (a[i + 1] != a[i]) //count grouped elements as a single element
      p[a[i]]++;

    BFL(i, 0, n)
    if (p[i] <= ans + 1 && p[i] != 0)
    {
      if (a[0] == i && a[n - 1] == i) // 2 of them are end elements, 2 less conversions
        ans = p[i] - 1;
      else if ((a[0] == i || a[n - 1] == i) && p[i] < ans + 1) // 1 of them end element, 1 less conversion
        ans = p[i];
      else if (p[i] < ans) // no end element, 0 less conversions
        ans = p[i] + 1;
    }

    cout << ans << en;
  }

  cerr << "Time taken: " << int((clock() * 1000.) / CLOCKS_PER_SEC) << "ms";
  return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define en '\n'
#define ll long int
#define BFL(i, a, b) for (i = a; i < b; i++)
void vec_i(string str, vector<int> &v)
{
  int a;
  istringstream stream(str);
  while (stream >> a)
    v.push_back(a);
}
int main()
{

  // ifstream cin("input.txt");
  // ofstream cout("output.txt");
  ll t;
  cin >> t;
  while (t--)
  {

    ll i, n, a[int(1 * 1e5)];
    cin >> n;

    ll p[int(1 * 1e5)] = {0}, ans = n;
    BFL(i, 0, n)
    cin >> a[i];

    // no of times a number occurs

    BFL(i, 0, n)
    if (i == (n - 1) || a[i + 1] != a[i]) //count grouped elements as a single element
      p[a[i]]++;

    BFL(i, 0, n)
    if (p[i] <= ans + 1 && p[i] != 0)
    {
      if (a[0] == i && a[n - 1] == i) // 2 of them are end elements, 2 less conversions
        ans = p[i] - 1;
      else if ((a[0] == i || a[n - 1] == i) && p[i] < ans + 1) // 1 of them end element, 1 less conversion
        ans = p[i];
      else if (p[i] < ans) // no end element, 0 less conversions
        ans = p[i] + 1;
    }

    cout << ans << en;
  }

  cerr << "Time taken: " << int((clock() * 1000.) / CLOCKS_PER_SEC) << "ms";
  return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define en '\n'
#define ll long int
#define BFL(i, a, b) for (i = a; i < b; i++)
void vec_i(string str, vector<int> &v)
{
  int a;
  istringstream stream(str);
  while (stream >> a)
    v.push_back(a);
}
int main()
{

  // ifstream cin("input.txt");
  // ofstream cout("output.txt");
  ll t;
  cin >> t;
  while (t--)
  {

    ll i, n, a[int(1 * 1e5)];
    cin >> n;

    ll p[int(1 * 1e5)] = {0}, ans = n;
    BFL(i, 0, n)
    cin >> a[i];

    a[n] = -1;

    // no of times a number occurs
    BFL(i, 0, n)
    if (i == (n - 1) || a[i + 1] != a[i]) //count grouped elements as a single element
      p[a[i]]++;

    BFL(i, 0, n)
    if (p[i] <= ans + 1 && p[i] != 0)
    {
      if (a[0] == i && a[n - 1] == i) // 2 of them are end elements, 2 less conversions
        ans = p[i] - 1;
      else if ((a[0] == i || a[n - 1] == i) && p[i] < ans + 1) // 1 of them end element, 1 less conversion
        ans = p[i];
      else if (p[i] < ans) // no end element, 0 less conversions
        ans = p[i] + 1;
    }

    cout << ans << en;
  }

  cerr << "Time taken: " << int((clock() * 1000.) / CLOCKS_PER_SEC) << "ms";
  return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define en '\n'
#define ll long int
#define BFL(i, a, b) for (i = a; i < b; i++)
void vec_i(string str, vector<int> &v)
{
  int a;
  istringstream stream(str);
  while (stream >> a)
    v.push_back(a);
}
int main()
{

  // ifstream cin("input.txt");
  // ofstream cout("output.txt");
  ll t;
  cin >> t;
  while (t--)
  {

    ll i, n, a[int(1 * 1e5)];
    cin >> n;

    ll p[int(1 * 1e5)] = {0}, ans = n;
    BFL(i, 0, n)
    cin >> a[i];

    // no of times a number occurs

    BFL(i, 0, n)
    if (a[i + 1] != a[i] || i == (n - 1)) //count grouped elements as a single element
      p[a[i]]++;

    BFL(i, 0, n)
    if (p[i] <= ans + 1 && p[i] != 0)
    {
      if (a[0] == i && a[n - 1] == i) // 2 of them are end elements, 2 less conversions
        ans = p[i] - 1;
      else if ((a[0] == i || a[n - 1] == i) && p[i] < ans + 1) // 1 of them end element, 1 less conversion
        ans = p[i];
      else if (p[i] < ans) // no end element, 0 less conversions
        ans = p[i] + 1;
    }

    cout << ans << en;
  }

  cerr << "Time taken: " << int((clock() * 1000.) / CLOCKS_PER_SEC) << "ms";
  return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define en '\n'
#define ll long int
#define BFL(i, a, b) for (i = a; i < b; i++)
void vec_i(string str, vector<int> &v)
{
  int a;
  istringstream stream(str);
  while (stream >> a)
    v.push_back(a);
}
int main()
{

  // ifstream cin("input.txt");
  // ofstream cout("output.txt");
  ll t;
  cin >> t;
  while (t--)
  {

    ll i, n, a[int(2 * 1e5) + 1];
    cin >> n;

    ll p[int(2 * 1e5) + 1] = {0}, ans = n;
    BFL(i, 0, n)
    cin >> a[i];

    a[n] = -1;

    // no of times a number occurs
    BFL(i, 0, n)
    if (i == (n - 1) || a[i + 1] != a[i]) //count grouped elements as a single element
      p[a[i]]++;

    BFL(i, 0, n + 1)
    if (p[i] <= ans + 1 && p[i] != 0)
    {
      if (a[0] == i && a[n - 1] == i) // 2 of them are end elements, 2 less conversions
        ans = p[i] - 1;
      else if ((a[0] == i || a[n - 1] == i) && p[i] < ans + 1) // 1 of them end element, 1 less conversion
        ans = p[i];
      else if (p[i] < ans) // no end element, 0 less conversions
        ans = p[i] + 1;
    }

    cout << ans << en;
  }

  cerr << "Time taken: " << int((clock() * 1000.) / CLOCKS_PER_SEC) << "ms";
  return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define en '\n'
#define ll long int
#define BFL(i, a, b) for (i = a; i < b; i++)
void vec_i(string str, vector<int> &v)
{
  int a;
  istringstream stream(str);
  while (stream >> a)
    v.push_back(a);
}
int main()
{

  // ifstream cin("input.txt");
  // ofstream cout("output.txt");
  ll t;
  cin >> t;
  while (t--)
  {

    ll i, n, a[int(1 * 1e5)];
    cin >> n;

    ll p[int(1 * 1e5)] = {0}, ans = n;
    BFL(i, 0, n)
    cin >> a[i];

    a[n] = -1;

    // no of times a number occurs
    BFL(i, 0, n)
    if (i == (n - 1) || a[i + 1] != a[i]) //count grouped elements as a single element
      p[a[i]]++;

    BFL(i, 0, n + 1)
    if (p[i] <= ans + 1 && p[i] != 0)
    {
      if (a[0] == i && a[n - 1] == i) // 2 of them are end elements, 2 less conversions
        ans = p[i] - 1;
      else if ((a[0] == i || a[n - 1] == i) && p[i] < ans + 1) // 1 of them end element, 1 less conversion
        ans = p[i];
      else if (p[i] < ans) // no end element, 0 less conversions
        ans = p[i] + 1;
    }

    cout << ans << en;
  }

  cerr << "Time taken: " << int((clock() * 1000.) / CLOCKS_PER_SEC) << "ms";
  return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define en '\n'
#define ll long long int
#define BFL(i, a, b) for (i = a; i < b; i++)
void vec_i(string str, vector<int> &v)
{
  int a;
  istringstream stream(str);
  while (stream >> a)
    v.push_back(a);
}
int main()
{

  // ifstream cin("input.txt");
  // ofstream cout("output.txt");
  ll t;
  cin >> t;
  while (t--)
  {

    ll i, n, a[int(1 * 1e5)];
    cin >> n;

    ll p[int(1 * 1e5)] = {0}, ans = n;
    BFL(i, 0, n)
    cin >> a[i];

    a[n] = -1;

    // no of times a number occurs
    BFL(i, 0, n)
    if (i == (n - 1) || a[i + 1] != a[i]) //count grouped elements as a single element
      p[a[i]]++;

    BFL(i, 0, n + 1)
    if (p[i] <= ans + 1 && p[i] != 0)
    {
      if (a[0] == i && a[n - 1] == i) // 2 of them are end elements, 2 less conversions
        ans = p[i] - 1;
      else if ((a[0] == i || a[n - 1] == i) && p[i] < ans + 1) // 1 of them end element, 1 less conversion
        ans = p[i];
      else if (p[i] < ans) // no end element, 0 less conversions
        ans = p[i] + 1;
    }

    cout << ans << en;
  }

  cerr << "Time taken: " << int((clock() * 1000.) / CLOCKS_PER_SEC) << "ms";
  return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define en '\n'
#define ll long int
#define BFL(i, a, b) for (i = a; i < b; i++)
void vec_i(string str, vector<int> &v)
{
  int a;
  istringstream stream(str);
  while (stream >> a)
    v.push_back(a);
}
int main()
{

  // ifstream cin("input.txt");
  // ofstream cout("output.txt");
  ll t;
  cin >> t;
  while (t--)
  {

    ll i, n, a[int(1 * 1e5)];

    ll p[int(1 * 1e5)] = {0}, ans = n;
    cin >> n;
    BFL(i, 0, n)
    cin >> a[i];

    // no of times a number occurs

    BFL(i, 0, n)
    p[a[i]]++;

    BFL(i, 0, n)
    if (p[i] < ans && p[i] != 0)
    {
      if (a[0] == i && a[n - 1] == i)
        ans = p[i] - 1;
      else if (a[0] == i || a[n - 1] == i)
        ans = p[i];
      else
        ans = p[i] + 1;
    }

    if (ans == n)
      cout << 0 << en;
    else
      cout << ans << en;
  }

  cerr << "Time taken: " << int((clock() * 1000.) / CLOCKS_PER_SEC) << "ms";
  return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define en '\n'
#define ll long int
#define BFL(i, a, b) for (i = a; i < b; i++)
void vec_i(string str, vector<int> &v)
{
  int a;
  istringstream stream(str);
  while (stream >> a)
    v.push_back(a);
}
int main()
{

  // ifstream cin("input.txt");
  // ofstream cout("output.txt");
  ll t;
  cin >> t;
  while (t--)
  {

    ll i, n, a[int(1 * 1e5)];

    ll p[int(1 * 1e5)] = {0}, ans = n;
    cin >> n;
    BFL(i, 0, n)
    cin >> a[i];

    // no of times a number occurs

    BFL(i, 0, n)
    p[a[i]]++;

    BFL(i, 0, n)
    if (p[i] <= ans && p[i] != 0)
    {
      if (a[0] == i && a[n - 1] == i)
        ans = p[i] - 1;
      else if (a[0] == i || a[n - 1] == i)
        ans = p[i];
      else if (p[i] < ans)
        ans = p[i] + 1;
    }

    if (ans == n)
      cout << 0 << en;
    else
      cout << ans << en;
  }

  cerr << "Time taken: " << int((clock() * 1000.) / CLOCKS_PER_SEC) << "ms";
  return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define en '\n'
#define ll long int
#define BFL(i, a, b) for (i = a; i < b; i++)
void vec_i(string str, vector<int> &v)
{
  int a;
  istringstream stream(str);
  while (stream >> a)
    v.push_back(a);
}
int main()
{

  // ifstream cin("input.txt");
  // ofstream cout("output.txt");
  ll t;
  cin >> t;
  while (t--)
  {

    ll i, n, a[int(1 * 1e5)];

    ll p[int(1 * 1e5)] = {0}, ans = n;
    cin >> n;
    BFL(i, 0, n)
    cin >> a[i];

    // no of times a number occurs

    BFL(i, 0, n)
    p[a[i]]++;

    BFL(i, 0, n)
    if (p[i] <= ans + 1 && p[i] != 0)
    {
      if (a[0] == i && a[n - 1] == i)
        ans = p[i] - 1;
      else if ((a[0] == i || a[n - 1] == i) && p[i] < ans)
        ans = p[i];
      else if (p[i] < ans)
        ans = p[i] + 1;
    }

    if (ans == n)
      cout << 0 << en;
    else
      cout << ans << en;
  }

  cerr << "Time taken: " << int((clock() * 1000.) / CLOCKS_PER_SEC) << "ms";
  return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define en '\n'
#define ll long int
#define BFL(i, a, b) for (i = a; i < b; i++)
void vec_i(string str, vector<int> &v)
{
  int a;
  istringstream stream(str);
  while (stream >> a)
    v.push_back(a);
}
int main()
{

  // ifstream cin("input.txt");
  // ofstream cout("output.txt");
  ll t;
  cin >> t;
  while (t--)
  {

    ll i, n, a[int(1 * 1e5)];

    ll p[int(1 * 1e5)] = {0}, ans = n;
    cin >> n;
    BFL(i, 0, n)
    cin >> a[i];

    // no of times a number occurs

    BFL(i, 0, n)
    p[a[i]]++;

    BFL(i, 0, n)
    if (p[i] <= ans + 1 && p[i] != 0)
    {
      if (a[0] == i && a[n - 1] == i)
        ans = p[i] - 1;
      else if (a[0] == i || a[n - 1] == i)
        ans = p[i];
      else if (p[i] < ans)
        ans = p[i] + 1;
    }

    if (ans == n)
      cout << 0 << en;
    else
      cout << ans << en;
  }

  cerr << "Time taken: " << int((clock() * 1000.) / CLOCKS_PER_SEC) << "ms";
  return 0;
}


#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
#include<queue>
#include<cmath>
#include<map>
#include<vector>
#include<stack>
#include<set>
#include<deque>
#define PI 3.1415
#define base 233
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int INF=0x3f3f3f3f;
const int eps=1e-8;
const ll mod=1e9+7;
const ll maxn=2e5+5;
const ull modd=212370440130137957ll;
int lowbit(int x){return x & -x;}
ll gcd(ll a,ll b){if(b==0)return a;return gcd(b,a%b);}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
ll quick_power(ll a,ll b,ll c){ll ans=1;a=a%c;while(b){if(b&1)ans=(ans*a)%c;b=b>>1;a=(a*a)%c;}return ans;}
bool isprime(int x){int flag=1;for(int i=2;i*i<=x;i++){if(x%i==0){flag=0;break;}}if(flag) return 1;else return 0;}

int t;
int n;
int a[maxn];

int main()
{
	cin>>t;
	while(t--)
	{
		cin>>n;
		memset(a,0,sizeof(a));
		map<int,int>num;
		num.clear();
		int maxx=0;
		for(int i=1;i<=n;i++)
		{
			cin>>a[i];
			maxx=max(maxx,a[i]);
			if(a[i-1]!=a[i])
				num[a[i]]++;
		}
		int flag=1;
		for(int i=2;i<=n;i++)
		{
			if(a[i]!=a[i-1])
			{
				flag=0;
				break;
			}
		}
		if(flag)
		{
			cout<<0<<endl;
			continue;
		}
		int tmp=INF;
		int cnt;
		for(int i=1;i<=n;i++)
		{
			if(num[i])
			{
				if(num[i]<tmp)
				{
					tmp=min(tmp,num[i]);
					cnt=i;
				}
			}
		}
		if(a[1]==a[n]&&num[a[1]]-2<tmp)
		{
			cout<<num[a[1]]-1<<endl;
			continue;
		}
		if(num[a[1]]-1<=tmp)
		{
			cout<<num[a[1]]<<endl;
			continue;
		}
		if(num[a[n]]-1<=tmp)
		{
			cout<<num[a[n]]<<endl;
			continue;
		}
		int ans=0;
		a[n+1]=cnt;
		for(int i=1;i<=n+1;i++)
		{
			if(a[i]==cnt)
			{
				if(a[i-1]!=cnt&&a[i-1]>0)
				{
					ans++;
				}
			}
		}
		cout<<ans<<endl;
	}
	return 0;
}


#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
#include<queue>
#include<cmath>
#include<map>
#include<vector>
#include<stack>
#include<set>
#include<deque>
#define PI 3.1415
#define base 233
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int INF=0x3f3f3f3f;
const int eps=1e-8;
const ll mod=1e9+7;
const ll maxn=2e5+5;
const ull modd=212370440130137957ll;
int lowbit(int x){return x & -x;}
ll gcd(ll a,ll b){if(b==0)return a;return gcd(b,a%b);}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
ll quick_power(ll a,ll b,ll c){ll ans=1;a=a%c;while(b){if(b&1)ans=(ans*a)%c;b=b>>1;a=(a*a)%c;}return ans;}
bool isprime(int x){int flag=1;for(int i=2;i*i<=x;i++){if(x%i==0){flag=0;break;}}if(flag) return 1;else return 0;}

int t;
int n;
int a[maxn];

int main()
{
	cin>>t;
	while(t--)
	{
		cin>>n;
		memset(a,0,sizeof(a));
		map<int,int>num;
		num.clear();
		int maxx=0;
		for(int i=1;i<=n;i++)
		{
			cin>>a[i];
			maxx=max(maxx,a[i]);
			if(a[i-1]!=a[i])
				num[a[i]]++;
		}
		num[a[1]]--;
		num[a[n]]--;
		if(num[a[1]]==0)
		{
			cout<<1<<endl;
			continue;
		}
		int flag=1;
		for(int i=2;i<=n;i++)
		{
			if(a[i]!=a[i-1])
			{
				flag=0;
				break;
			}
		}
		if(flag)
		{
			cout<<0<<endl;
			continue;
		}
		int tmp=INF;
		int cnt;
		for(int i=1;i<=n;i++)
		{
			if(num[i])
			{
				if(num[i]<tmp)
				{
					tmp=min(tmp,num[i]);
					cnt=i;
				}
			}
		}
		cout<<tmp+1<<endl;
	}
	return 0;
}


#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
#include<queue>
#include<cmath>
#include<map>
#include<vector>
#include<stack>
#include<set>
#include<deque>
#define PI 3.1415
#define base 233
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int INF=0x3f3f3f3f;
const int eps=1e-8;
const ll mod=1e9+7;
const ll maxn=2e5+5;
const ull modd=212370440130137957ll;
int lowbit(int x){return x & -x;}
ll gcd(ll a,ll b){if(b==0)return a;return gcd(b,a%b);}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
ll quick_power(ll a,ll b,ll c){ll ans=1;a=a%c;while(b){if(b&1)ans=(ans*a)%c;b=b>>1;a=(a*a)%c;}return ans;}
bool isprime(int x){int flag=1;for(int i=2;i*i<=x;i++){if(x%i==0){flag=0;break;}}if(flag) return 1;else return 0;}

int t;
int n;
int a[maxn];

int main()
{
	cin>>t;
	while(t--)
	{
		cin>>n;
		map<int,int>num;
		num.clear();
		int maxx=0;
		for(int i=1;i<=n;i++)
		{
			cin>>a[i];
			maxx=max(maxx,a[i]);
			if(a[i-1]!=a[i])
				num[a[i]]++;
		}
		int flag=1;
		for(int i=2;i<=n;i++)
		{
			if(a[i]!=a[i-1])
			{
				flag=0;
				break;
			}
		}
		if(flag)
		{
			cout<<0<<endl;
			continue;
		}
		int tmp=INF;
		int cnt;
		if(a[1]==a[n]&&num[a[1]]==3)
		{
			cout<<2<<endl;
			continue;
		}
		if(a[1]==a[n]&&num[a[1]]==2)
		{
			cout<<1<<endl;
			continue;
		}
		for(int i=1;i<=n;i++)
		{
			if(num[i])
			{
				tmp=min(tmp,num[i]);
				cnt=i;
			}
		}
		int ans;
		if((a[1]==cnt||a[n]==cnt)&&num[cnt]==1)
		{
			cout<<1<<endl;continue;
		}
		if(num[cnt]==1&&(a[1]!=cnt||a[n]!=cnt))
		{
			cout<<2<<endl;
			continue;
		}
		if(a[1]==cnt&&a[n]==cnt)
		{
			ans=tmp-2+1;
			cout<<ans<<endl;
		}
		else
		{
			if(a[1]==cnt||a[n]==cnt)
				ans=tmp;
			else
				ans=tmp+1;
			cout<<ans<<endl;
		}

	}
	return 0;
}


#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
#include<queue>
#include<cmath>
#include<map>
#include<vector>
#include<stack>
#include<set>
#include<deque>
#define PI 3.1415
#define base 233
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int INF=0x3f3f3f3f;
const int eps=1e-8;
const ll mod=1e9+7;
const ll maxn=2e5+5;
const ull modd=212370440130137957ll;
int lowbit(int x){return x & -x;}
ll gcd(ll a,ll b){if(b==0)return a;return gcd(b,a%b);}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
ll quick_power(ll a,ll b,ll c){ll ans=1;a=a%c;while(b){if(b&1)ans=(ans*a)%c;b=b>>1;a=(a*a)%c;}return ans;}
bool isprime(int x){int flag=1;for(int i=2;i*i<=x;i++){if(x%i==0){flag=0;break;}}if(flag) return 1;else return 0;}

int t;
int n;
int a[maxn];

int main()
{
	cin>>t;
	while(t--)
	{
		cin>>n;
		memset(a,0,sizeof(a));
		map<int,int>num;
		num.clear();
		int maxx=0;
		for(int i=1;i<=n;i++)
		{
			cin>>a[i];
			maxx=max(maxx,a[i]);
			if(a[i-1]!=a[i])
				num[a[i]]++;
		}
		num[a[1]]--;
		num[a[n]]--;
		if(num[a[1]]==0)
		{
			cout<<1<<endl;
			continue;
		}
		int flag=1;
		for(int i=2;i<=n;i++)
		{
			if(a[i]!=a[i-1])
			{
				flag=0;
				break;
			}
		}
		if(flag)
		{
			cout<<0<<endl;
			continue;
		}
		int tmp=INF;
		int cnt;
		for(int i=1;i<=n;i++)
		{
			if(num[i])
			{
				if(num[i]<tmp)
				{
					tmp=min(tmp,num[i]);
					cnt=i;
				}
			}
		}
		int ans=0;
		a[n+1]=cnt;
		for(int i=1;i<=n+1;i++)
		{
			if(a[i]==cnt)
			{
				if(a[i-1]!=cnt&&a[i-1]>0)
				{
					ans++;
				}
			}
		}
		cout<<ans<<endl;
	}
	return 0;
}


#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
#include<queue>
#include<cmath>
#include<map>
#include<vector>
#include<stack>
#include<set>
#include<deque>
#define PI 3.1415
#define base 233
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int INF=0x3f3f3f3f;
const int eps=1e-8;
const ll mod=1e9+7;
const ll maxn=2e5+5;
const ull modd=212370440130137957ll;
int lowbit(int x){return x & -x;}
ll gcd(ll a,ll b){if(b==0)return a;return gcd(b,a%b);}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
ll quick_power(ll a,ll b,ll c){ll ans=1;a=a%c;while(b){if(b&1)ans=(ans*a)%c;b=b>>1;a=(a*a)%c;}return ans;}
bool isprime(int x){int flag=1;for(int i=2;i*i<=x;i++){if(x%i==0){flag=0;break;}}if(flag) return 1;else return 0;}

int t;
int n;
int a[maxn];

int main()
{
	cin>>t;
	while(t--)
	{
		cin>>n;
		memset(a,0,sizeof(a));
		map<int,int>num;
		num.clear();
		int maxx=0;
		for(int i=1;i<=n;i++)
		{
			cin>>a[i];
			maxx=max(maxx,a[i]);
			if(a[i-1]!=a[i])
				num[a[i]]++;
		}
		num[a[1]]--;
		num[a[n]]--;
		if(num[a[1]]==0||num[a[n]]==0)
		{
			cout<<1<<endl;
			continue;
		}
		int flag=1;
		for(int i=2;i<=n;i++)
		{
			if(a[i]!=a[i-1])
			{
				flag=0;
				break;
			}
		}
		if(flag)
		{
			cout<<0<<endl;
			continue;
		}
		int tmp=INF;
		int cnt;
		for(int i=1;i<=n;i++)
		{
			if(num[i])
			{
				if(num[i]<tmp)
				{
					tmp=min(tmp,num[i]);
					cnt=i;
				}
			}
		}
		cout<<tmp+1<<endl;
	}
	return 0;
}


#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
#include<queue>
#include<cmath>
#include<map>
#include<vector>
#include<stack>
#include<set>
#include<deque>
#define PI 3.1415
#define base 233
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int INF=0x3f3f3f3f;
const int eps=1e-8;
const ll mod=1e9+7;
const ll maxn=2e5+5;
const ull modd=212370440130137957ll;
int lowbit(int x){return x & -x;}
ll gcd(ll a,ll b){if(b==0)return a;return gcd(b,a%b);}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
ll quick_power(ll a,ll b,ll c){ll ans=1;a=a%c;while(b){if(b&1)ans=(ans*a)%c;b=b>>1;a=(a*a)%c;}return ans;}
bool isprime(int x){int flag=1;for(int i=2;i*i<=x;i++){if(x%i==0){flag=0;break;}}if(flag) return 1;else return 0;}

int t;
int n;
int a[maxn];

int main()
{
	cin>>t;
	while(t--)
	{
		cin>>n;
		map<int,int>num;
		num.clear();
		int maxx=0;
		for(int i=1;i<=n;i++)
		{
			cin>>a[i];
			maxx=max(maxx,a[i]);
			if(a[i-1]!=a[i])
				num[a[i]]++;
		}
		int flag=1;
		for(int i=2;i<=n;i++)
		{
			if(a[i]!=a[i-1])
			{
				flag=0;
				break;
			}
		}
		if(flag)
		{
			cout<<0<<endl;
			continue;
		}
		int tmp=INF;
		int cnt;
		if(a[1]==a[n]&&num[a[1]]==3)
		{
			cout<<2<<endl;
			continue;
		}
		if(a[1]==a[n]&&num[a[1]]==2)
		{
			cout<<1<<endl;
			continue;
		}
		for(int i=1;i<=n;i++)
		{
			if(num[i])
			{	if(num[i]<tmp)
				{
					tmp=min(tmp,num[i]);
					cnt=i;
				}
			}
		}
		int ans=0;
		a[n+1]=cnt;
		for(int i=1;i<=n+1;i++)
		{
			if(a[i]==cnt)
			{
				if(a[i-1]!=cnt&&a[i-1])
				{
					ans++;
				}
			}
		}
		cout<<ans<<endl;
	}
	return 0;
}


#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
#include<queue>
#include<cmath>
#include<map>
#include<vector>
#include<stack>
#include<set>
#include<deque>
#define PI 3.1415
#define base 233
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int INF=0x3f3f3f3f;
const int eps=1e-8;
const ll mod=1e9+7;
const ll maxn=2e5+5;
const ull modd=212370440130137957ll;
int lowbit(int x){return x & -x;}
ll gcd(ll a,ll b){if(b==0)return a;return gcd(b,a%b);}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
ll quick_power(ll a,ll b,ll c){ll ans=1;a=a%c;while(b){if(b&1)ans=(ans*a)%c;b=b>>1;a=(a*a)%c;}return ans;}
bool isprime(int x){int flag=1;for(int i=2;i*i<=x;i++){if(x%i==0){flag=0;break;}}if(flag) return 1;else return 0;}

int t;
int n;
int a[maxn];

int main()
{
	cin>>t;
	while(t--)
	{
		cin>>n;
		map<int,int>num;
		num.clear();
		int maxx=0;
		for(int i=1;i<=n;i++)
		{
			cin>>a[i];
			maxx=max(maxx,a[i]);
			if(a[i-1]!=a[i])
				num[a[i]]++;
		}
		int flag=1;
		for(int i=2;i<=n;i++)
		{
			if(a[i]!=a[i-1])
			{
				flag=0;
				break;
			}
		}
		if(flag)
		{
			cout<<0<<endl;
			continue;
		}
		int tmp=INF;
		int cnt;
		if(a[1]==a[n]&&num[a[1]]==3)
		{
			cout<<2<<endl;
			continue;
		}
		if(a[1]==a[n]&&num[a[1]]==2)
		{
			cout<<1<<endl;
			continue;
		}
		for(int i=1;i<=n;i++)
		{
			if(num[i])
			{	if(num[i]<tmp)
				{
					tmp=min(tmp,num[i]);
					cnt=i;
				}
			}
		}
		int ans;
		if((a[1]==cnt||a[n]==cnt)&&num[cnt]==1)
		{
			cout<<1<<endl;continue;
		}
		if(num[cnt]==1&&(a[1]!=cnt||a[n]!=cnt))
		{
			cout<<2<<endl;
			continue;
		}
		if(a[1]==cnt&&a[n]==cnt)
		{
			ans=tmp-2+1;
			cout<<ans<<endl;
		}
		else
		{
			if(a[1]==cnt||a[n]==cnt)
				ans=tmp;
			else
				ans=tmp+1;
			cout<<ans<<endl;
		}

	}
	return 0;
}


#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
#include<queue>
#include<cmath>
#include<map>
#include<vector>
#include<stack>
#include<set>
#include<deque>
#define PI 3.1415
#define base 233
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int INF=0x3f3f3f3f;
const int eps=1e-8;
const ll mod=1e9+7;
const ll maxn=2e5+5;
const ull modd=212370440130137957ll;
int lowbit(int x){return x & -x;}
ll gcd(ll a,ll b){if(b==0)return a;return gcd(b,a%b);}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
ll quick_power(ll a,ll b,ll c){ll ans=1;a=a%c;while(b){if(b&1)ans=(ans*a)%c;b=b>>1;a=(a*a)%c;}return ans;}
bool isprime(int x){int flag=1;for(int i=2;i*i<=x;i++){if(x%i==0){flag=0;break;}}if(flag) return 1;else return 0;}

int t;
int n;
int a[maxn];

int main()
{
	cin>>t;
	while(t--)
	{
		cin>>n;
		map<int,int>num;
		num.clear();
		int maxx=0;
		for(int i=1;i<=n;i++)
		{
			cin>>a[i];
			maxx=max(maxx,a[i]);
			if(a[i-1]!=a[i])
				num[a[i]]++;
		}
		int tmp=INF;
		int cnt;
		if(a[1]==a[n]&&num[a[1]]==n)
		{
			cout<<0<<endl;
			continue;
		}
		if(a[1]==a[n]&&num[a[1]]==3)
		{
			cout<<2<<endl;
			continue;
		}
		if(a[1]==a[n]&&num[a[1]]==2)
		{
			cout<<1<<endl;
			continue;
		}
		for(int i=1;i<=n;i++)
		{
			if(num[i])
			{
				tmp=min(tmp,num[i]);
				cnt=i;
			}
		}
		int ans;
		if(a[1]==cnt&&a[n]==cnt)
		{
			ans=tmp-2+1;
			cout<<ans<<endl;
		}
		else
		{
			if(a[1]==cnt||a[n]==cnt)
				ans=tmp;
			else
				ans=tmp+1;
			cout<<ans<<endl;
		}

	}
	return 0;
}


#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
#include<queue>
#include<cmath>
#include<map>
#include<vector>
#include<stack>
#include<set>
#include<deque>
#define PI 3.1415
#define base 233
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int INF=0x3f3f3f3f;
const int eps=1e-8;
const ll mod=1e9+7;
const ll maxn=2e5+5;
const ull modd=212370440130137957ll;
int lowbit(int x){return x & -x;}
ll gcd(ll a,ll b){if(b==0)return a;return gcd(b,a%b);}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
ll quick_power(ll a,ll b,ll c){ll ans=1;a=a%c;while(b){if(b&1)ans=(ans*a)%c;b=b>>1;a=(a*a)%c;}return ans;}
bool isprime(int x){int flag=1;for(int i=2;i*i<=x;i++){if(x%i==0){flag=0;break;}}if(flag) return 1;else return 0;}

int t;
int n;
int a[maxn];

int main()
{
	cin>>t;
	while(t--)
	{
		cin>>n;
		memset(a,0,sizeof(a));
		map<int,int>num;
		num.clear();
		int maxx=0;
		for(int i=1;i<=n;i++)
		{
			cin>>a[i];
			maxx=max(maxx,a[i]);
			if(a[i-1]!=a[i])
				num[a[i]]++;
		}
		int flag=1;
		for(int i=2;i<=n;i++)
		{
			if(a[i]!=a[i-1])
			{
				flag=0;
				break;
			}
		}
		if(flag)
		{
			cout<<0<<endl;
			continue;
		}
		if(a[1]==a[n]&&num[a[1]]==2)
		{
			cout<<1<<endl;
			continue;
		}
		int tmp=INF;
		int cnt;
		for(int i=1;i<=n;i++)
		{
			if(num[i])
			{
				if(num[i]<tmp)
				{
					tmp=min(tmp,num[i]);
					cnt=i;
				}
			}
		}
		int ans=0;
		a[n+1]=cnt;
		for(int i=1;i<=n+1;i++)
		{
			if(a[i]==cnt)
			{
				if(a[i-1]!=cnt&&a[i-1]>0)
				{
					ans++;
				}
			}
		}
		cout<<ans<<endl;
	}
	return 0;
}


#include<cstdio>
#include<math.h>
#include<iostream>
#include<algorithm>
#include<queue>
#include<cstring>
#include<stack>
#include<map>
#include<set>
#include<cstdlib>
#include<vector>
#include<bitset>
#define inf 0x3f3f3f3f
#define pi acos(-1.0)
#define LL __int128
#define mem(a,b) memset(a,b,sizeof(a));
using namespace std;
typedef long long ll;
typedef double db;
const double eps = 1e-8;
const int mod = 1e9+7;
const int maxn = 2e5+5;
int t,n,a[maxn],b[maxn];
int main(){
	scanf("%d",&t);
	while(t--){
		cin >> n;
		for(int i = 1;i <= n;i++){
			cin >> a[i];
			if(a[i] != a[i-1] && i != 1 && i != n){
				b[a[i]]++;
			}
		}
		if(a[n] == a[n-1]){
			b[a[n]]--;
		}
		int flag = 1;
		for(int i = 1;i < n;i++){
			if(a[i] != a[i+1]){
				flag = 0;
				break;
			}
		}
		if(flag || n == 1){
			cout << "0\n";
			continue;
		}
		int ans = n;
		for(int i = 1;i <= n;i++){
		//	cout << b[a[i]] << endl;
			ans = min(ans,b[a[i]]+1);
		}
		printf("%d\n",ans);
		for(int i = 1;i <= n;i++){
			b[a[i]] = 0;
			a[i] = 0;
		}

	}
	return 0;
}


#include<cstdio>
#include<math.h>
#include<iostream>
#include<algorithm>
#include<queue>
#include<cstring>
#include<stack>
#include<map>
#include<set>
#include<cstdlib>
#include<vector>
#include<bitset>
#define inf 0x3f3f3f3f
#define pi acos(-1.0)
#define LL __int128
#define mem(a,b) memset(a,b,sizeof(a));
using namespace std;
typedef long long ll;
typedef double db;
const double eps = 1e-8;
const int mod = 1e9+7;
const int maxn = 2e5+5;
int t,n,a[maxn],b[maxn];
int main(){
	scanf("%d",&t);
	while(t--){
		cin >> n;
		for(int i = 1;i <= n;i++){
			cin >> a[i];
			if(a[i] != a[i-1] && i != 1 && i != n){
				b[a[i]]++;
			}
		}
		int flag = 1;
		for(int i = 1;i < n;i++){
			if(a[i] != a[i+1]){
				flag = 0;
				break;
			}
		}
		if(flag || n == 1){
			cout << "0\n";
			continue;
		}
		int ans = n;
		for(int i = 1;i <= n;i++){
			ans = min(ans,b[a[i]]+1);
		}
		printf("%d\n",ans);
		for(int i = 1;i <= n;i++){
			b[a[i]] = 0;
			a[i] = 0;
		}

	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef double db;
const int maxn = 2e5+5;
int t,n,a[maxn],b[maxn],vis[maxn];
int main(){
	scanf("%d",&t);
	while(t--){
		cin >> n;
		for(int i = 1;i <= n;i++){
			cin >> a[i];
			if(!b[a[i]]){
				vis[a[i]] = i;
				b[a[i]] = 1;
			}
			else{
				if(vis[a[i]] == i-1){
					vis[a[i]] = i;
				}
				else{
					b[a[i]]++;
					vis[a[i]] = i;
				}
			}
		}
		int ans = 1e9;
		for(int i = 1;i <= n;i++){
			if(i == 1 || i == n)	b[a[i]]--;
			ans = min(ans,b[a[i]]+1);
		}
		cout << ans << endl;
	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef double db;
const int maxn = 2e5+5;
int t,n,a[maxn],b[maxn];
int main(){
	scanf("%d",&t);
	while(t--){
		cin >> n;
		for(int i = 1;i <= n;i++){
			cin >> a[i];
			if(a[i] != a[i-1] && i != 1 && i != n){
				b[a[i]]++;
			}
		}
		int flag = 1;
		for(int i = 1;i < n;i++){
			if(a[i] != a[i+1]){
				flag = 0;
				break;
			}
		}
		if(flag){
			cout << "0\n";
			continue;
		}
		int ans = 1e9;
		for(int i = 1;i <= n;i++){
			ans = min(ans,b[a[i]]+1);
		}
		printf("%d\n",ans);
		for(int i = 1;i <= n;i++){
			b[a[i]] = 0;
			a[i] = 0;
		}

	}
	return 0;
}


#include<cstdio>
#include<math.h>
#include<iostream>
#include<algorithm>
#include<queue>
#include<cstring>
#include<stack>
#include<map>
#include<set>
#include<cstdlib>
#include<vector>
#include<bitset>
#define inf 0x3f3f3f3f
#define pi acos(-1.0)
#define LL __int128
#define mem(a,b) memset(a,b,sizeof(a));
using namespace std;
typedef long long ll;
typedef double db;
const double eps = 1e-8;
const int mod = 1e9+7;
const int maxn = 2e5+5;
int t,n,a[maxn],b[maxn];
int main(){
	scanf("%d",&t);
	while(t--){
		cin >> n;
		for(int i = 1;i <= n;i++){
			cin >> a[i];
			if(a[i] != a[i-1] && i != 1 && i != n){
				b[a[i]]++;
			}
		}
		if(a[n] == a[n-1] && b[a[n]]){
			b[a[n]]--;
		}
		int flag = 1;
		for(int i = 1;i < n;i++){
			if(a[i] != a[i+1]){
				flag = 0;
				break;
			}
		}
		if(flag || n == 1){
			cout << "0\n";
			continue;
		}
		int ans = n;
		for(int i = 1;i <= n;i++){
		//	cout << b[a[i]] << endl;
			ans = min(ans,b[a[i]]+1);
		}
		printf("%d\n",ans);
		for(int i = 1;i <= n;i++){
			b[a[i]] = 0;
			a[i] = 0;
		}

	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef double db;
const int maxn = 2e5+5;
stack<int>st;
int a[maxn],len=0,b[maxn];
map<int,int>mp;
int main()
{
	int t,x;
	cin>>t;
	while(t--)
	{
		int n;
		cin>>n;
		int flag=0;
		mp.clear();
		cin>>a[1];
		int len=1;
		mp[a[1]]++;
		int zz=0;
		for(int i=2;i<=n;i++)
		{
			cin>>x;
			if(x!=a[len])
			{
				a[++len]=x;
				mp[x]++;
			}
			if(x==a[1]) zz++;
		}
		if(zz==n-1) { puts("0"); continue;}
		if(mp[a[1]]==1||mp[a[len]]==1) {puts("1"); continue;}
		int ans=0x3f3f3f;
		if(a[1]==a[len]) ans=mp[a[1]]-1;
		else ans=min(mp[a[1]],mp[a[len]]);
		for(int i=1;i<=len;i++)
		{
			ans=min(ans,mp[a[i]]+1);
		}
		printf("%d\n",ans);
	}
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef double db;
const int maxn = 2e5+5;
int t,n,a[maxn],b[maxn];
int main(){
	scanf("%d",&t);
	while(t--){
		cin >> n;
		for(int i = 1;i <= n;i++){
			cin >> a[i];
			if(a[i] != a[i-1] && i != 1 && i != n){
				b[a[i]]++;
			}
		}
		int flag = 1;
		for(int i = 1;i < n;i++){
			if(a[i] != a[i+1]){
				flag = 0;
				break;
			}
		}
		if(flag || n == 1){
			cout << "0\n";
			continue;
		}
		int ans = n;
		for(int i = 1;i <= n;i++){
			ans = min(ans,b[a[i]]+1);
		}
		printf("%d\n",ans);
		for(int i = 1;i <= n;i++){
			b[a[i]] = 0;
			a[i] = 0;
		}

	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef double db;
const int maxn = 2e5+5;
int t,n,a[maxn],b[maxn],vis[maxn];
int main(){
	scanf("%d",&t);
	while(t--){
		cin >> n;
		for(int i = 1;i <= n;i++){
			cin >> a[i];
			if(a[i] != a[i-1] && i != 1 && i != n){
				b[a[i]]++;
			}
		}
		int flag = 1;
		for(int i = 1;i < n;i++){
			if(a[i] != a[i+1]){
				flag = 0;
				break;
			}
		}
		if(flag){
			cout << "0\n";
			continue;
		}
		int ans = 1e9;
		for(int i = 1;i <= n;i++){
			ans = min(ans,b[a[i]]+1);
		}
		printf("%d\n",ans);
		for(int i = 1;i <= n;i++){
			b[a[i]] = 0;vis[a[i]] = 0;
		}

	}
	return 0;
}


#include<cstdio>
#include<math.h>
#include<iostream>
#include<algorithm>
#include<queue>
#include<cstring>
#include<stack>
#include<map>
#include<set>
#include<cstdlib>
#include<vector>
#include<bitset>
#define inf 0x3f3f3f3f
#define pi acos(-1.0)
#define LL __int128
#define mem(a,b) memset(a,b,sizeof(a));
using namespace std;
typedef long long ll;
typedef double db;
const double eps = 1e-8;
const int mod = 1e9+7;
const int maxn = 2e5+5;
int t,n,a[maxn],b[maxn],vis[maxn];
int main(){
	scanf("%d",&t);
	while(t--){
		cin >> n;
		for(int i = 1;i <= n;i++){
			cin >> a[i];
			if(!b[a[i]]){
				vis[a[i]] = i;
				b[a[i]] = 1;
			}
			else{
				if(vis[a[i]] == i-1){
					vis[a[i]] = i;
				}
				else{
					b[a[i]]++;
					vis[a[i]] = i;
				}
			}
		}
		int ans = 1e9;
		for(int i = 1;i <= n;i++){
			if(i == 1 || i == n)	b[a[i]]--;
			ans = min(ans,b[a[i]]+1);
		}
		printf("%d\n",ans);
		for(int i = 1;i <= n;i++){
			b[a[i]] = 0;vis[a[i]] = 0;
		}

	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef double db;
const int maxn = 2e5+5;
int t,n,a[maxn],b[maxn],vis[maxn];
int main(){
	scanf("%d",&t);
	while(t--){
		memset(b,0,sizeof(b));
		memset(vis,0,sizeof(vis));
		cin >> n;
		for(int i = 1;i <= n;i++){
			cin >> a[i];
			if(!b[a[i]]){
				vis[a[i]] = i;
				b[a[i]] = 1;
			}
			else{
				if(vis[a[i]] == i-1){
					vis[a[i]] = i;
				}
				else{
					b[a[i]]++;
					vis[a[i]] = i;
				}
			}
		}
		int ans = 1e9;
		for(int i = 1;i <= n;i++){
			if(i == 1 || i == n)	b[a[i]]--;
			ans = min(ans,b[a[i]]+1);
		}
		cout << ans << endl;
	}
	return 0;
}


#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<cmath>
#include<numeric>
#include<set>
#include<assert.h>
#include<queue>
#include<stack>
#include<unordered_set>

using namespace std;

#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
    *this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "

#define REP(i,a,b) for(int i=a; i<b;++i)
#define endl "\n"
#define F first
#define S second
#define MP make_pair
#define PB push_back
#define all(a) a.begin(),a.end()
#define sz(a) int((a).size())
#define tr(c,i) for(typeof(c).begin() i = c.begin(); i != c.end(); i++)
#define present(c,x) (c.find(x) != c.end())
#define cpresent(c,x) (find(all(c,x) != c.end())

typedef pair< int,int > ii;
typedef vector<int> vi;
typedef long long ll;
typedef vector< vector<int> > vvi;
int INF = 1e9;

void calculate() {

}
int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int T;
    cin >> T;
    while(T--){
        int n;
        cin >> n;
        vi data(n);
        REP(i,0,n){
            cin >> data[i];
        }

        data.erase(unique(all(data)),data.end());
        //debug() << imie(data);
        n = data.size();

        vi res(n+1,1);
        REP(i,0,n){
          res[data[i]]++;
        }
        res[data[0]]--;
        res[data[n-1]]--;

        int ans = INF;
        REP(i,0,n){
          ans = min(ans,res[data[i]]);
        }
        cout << ans << endl;
    }
}


#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<cmath>
#include<numeric>
#include<set>
#include<assert.h>
#include<queue>
#include<stack>
#include<unordered_set>

using namespace std;

#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
    *this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "

#define REP(i,a,b) for(int i=a; i<b;++i)
#define endl "\n"
#define F first
#define S second
#define MP make_pair
#define PB push_back
#define all(a) a.begin(),a.end()
#define sz(a) int((a).size())
#define tr(c,i) for(typeof(c).begin() i = c.begin(); i != c.end(); i++)
#define present(c,x) (c.find(x) != c.end())
#define cpresent(c,x) (find(all(c,x) != c.end())

typedef pair< int,int > ii;
typedef vector<int> vi;
typedef long long ll;
typedef vector< vector<int> > vvi;
int INF = 1e9;

void calculate() {

}
int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int T;
    cin >> T;
    while(T--){
        int n;
        cin >> n;
        vi data;
        int d,p;
        cin >> d;
        data.PB(d);
        p=d;
        REP(i,1,n){
            cin >> d;
            if(d != p) {
                data.PB(d);
                p=d;
            }
        }
        n = data.size();
        debug() << imie(data);
        int c = count(all(data),data[0]);
        // if everything is same
        if(c == n) {
            cout << 0 << endl;
            continue;
        }
        int ans = INF;
        if (data[0] == data[n-1]) {
            ans = c - 1;
        }
        REP(i,0,n){
            c = count(all(data),data[i]);
            if (c == 1) {
                if(i==0 or i == n-1) {
                    ans = c;
                    break;
                } else {
                    ans = 2;
                }

            } else {
                if(data[i] == data[0] or data[i] == data[n-1])
                {
                    c--;
                }
                ans = min(ans,c+1);
            }
            if (ans==1) break;
        }
        cout << ans << endl;
    }
}


#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<cmath>
#include<numeric>
#include<set>
#include<assert.h>
#include<queue>
#include<stack>
#include<unordered_set>

using namespace std;

#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
    *this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "

#define REP(i,a,b) for(int i=a; i<b;++i)
#define endl "\n"
#define F first
#define S second
#define MP make_pair
#define PB push_back
#define all(a) a.begin(),a.end()
#define sz(a) int((a).size())
#define tr(c,i) for(typeof(c).begin() i = c.begin(); i != c.end(); i++)
#define present(c,x) (c.find(x) != c.end())
#define cpresent(c,x) (find(all(c,x) != c.end())

typedef pair< int,int > ii;
typedef vector<int> vi;
typedef long long ll;
typedef vector< vector<int> > vvi;
int INF = 1e9;

void calculate() {

}
int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int T;
    cin >> T;
    while(T--){
        int n;
        cin >> n;
        vi data(n);
        REP(i,0,n){
            cin >> data[i];
        }
        vi res(n+1,1);

        data.erase(unique(all(data)),data.end());
        //debug() << imie(data);
        n = data.size();

        REP(i,0,n){
          res[data[i]]++;
        }
        res[data[0]]--;
        res[data[n-1]]--;

        int ans = INF;
        REP(i,0,n){
          ans = min(ans,res[data[i]]);
        }
        cout << ans << endl;
    }
}


#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<cmath>
#include<numeric>
#include<set>
#include<assert.h>
#include<queue>
#include<stack>
#include<unordered_set>

using namespace std;

#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
    *this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "

#define REP(i,a,b) for(int i=a; i<b;++i)
#define endl "\n"
#define F first
#define S second
#define MP make_pair
#define PB push_back
#define all(a) a.begin(),a.end()
#define sz(a) int((a).size())
#define tr(c,i) for(typeof(c).begin() i = c.begin(); i != c.end(); i++)
#define present(c,x) (c.find(x) != c.end())
#define cpresent(c,x) (find(all(c,x) != c.end())

typedef pair< int,int > ii;
typedef vector<int> vi;
typedef long long ll;
typedef vector< vector<int> > vvi;
int INF = 1e9;

void calculate() {

}
int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int T;
    cin >> T;
    while(T--){
        int n;
        cin >> n;
        vi data;
        int d,p;
        cin >> d;
        data.PB(d);
        p=d;
        REP(i,1,n){
            cin >> d;
            if(d != p) {
                data.PB(d);
                p=d;
            }
        }
        n = data.size();
        debug() << imie(data);
        int c = count(all(data),data[0]);
        // if everything is same
        if(c == n) {
            cout << 0 << endl;
            continue;
        }
        int ans = INF;
        if (data[0] == data[n-1]) {
            ans = c - 1;
        }
        REP(i,0,n){
            c = count(all(data),data[i]);
            if (c == 1) {
                if(i==0 or i == n-1) {
                    ans = c;
                    break;
                } else {
                    ans = 2;
                    break;
                }

            } else {
                if(data[i] == data[0] or data[i] == data[n-1])
                {
                    c--;
                }
                ans = min(ans,c+1);
            }
            if (ans==1) break;
        }
        cout << ans << endl;
    }
}


#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<cmath>
#include<numeric>
#include<set>
#include<assert.h>
#include<queue>
#include<stack>
#include<unordered_set>

using namespace std;

#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
    *this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "

#define REP(i,a,b) for(int i=a; i<b;++i)
#define endl "\n"
#define F first
#define S second
#define MP make_pair
#define PB push_back
#define all(a) a.begin(),a.end()
#define sz(a) int((a).size())
#define tr(c,i) for(typeof(c).begin() i = c.begin(); i != c.end(); i++)
#define present(c,x) (c.find(x) != c.end())
#define cpresent(c,x) (find(all(c,x) != c.end())

typedef pair< int,int > ii;
typedef vector<int> vi;
typedef long long ll;
typedef vector< vector<int> > vvi;
int INF = 1e9;

void calculate() {

}
int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int T;
    cin >> T;
    while(T--){
        int n;
        cin >> n;
        vi data;
        int d,p;
        cin >> d;
        data.PB(d);
        p=d;
        //vi countd(2e5);
        REP(i,1,n){
            cin >> d;
            if(d != p) {
                data.PB(d);
                //countd[d]++;
                p=d;
            }
        }
        n = data.size();
        //debug() << imie(data);
        bool inc;
        int ans = INF;
        REP(i,0,n){
            int current = data[i];
            inc = true;
            int counter = 0;
            REP(j,0,n){
                int check = data[j];
                if(check != current){
                    if(inc) {
                        counter++;
                        inc = false;
                        //cout << "data not match: " << check << " current : " << current << endl;
                    }

                } else {
                    //cout << "data match: " << check << " current : " << current << endl;
                    inc = true;
                }
            }
            //cout << counter << endl;
            ans = min(ans,counter);
        }
        //debug() << imie(ans);

        // int c = count(all(data),data[0]);
        // // if everything is same
        // if(c == n) {
        //     cout << 0 << endl;
        //     continue;
        // }
        // int ans = INF;
        // if (data[0] == data[n-1]) {
        //     ans = c - 1;
        // }
        // REP(i,0,n){
        //     // c = count(all(data),data[i]);
        //     if (c == 1) {
        //         if(i==0 or i == n-1) {
        //             ans = c;
        //             break;
        //         } else {
        //             ans = 2;
        //         }

        //     } else {
        //         if(data[i] == data[0] or data[i] == data[n-1])
        //         {
        //             c--;
        //         }
        //         ans = min(ans,c+1);
        //     }
        //     if (ans==1) break;
        // }
        cout << ans << endl;
    }
}


#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<cmath>
#include<numeric>
#include<set>
#include<assert.h>
#include<queue>
#include<stack>
#include<unordered_set>

using namespace std;

#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
    *this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "

#define REP(i,a,b) for(int i=a; i<b;++i)
#define endl "\n"
#define F first
#define S second
#define MP make_pair
#define PB push_back
#define all(a) a.begin(),a.end()
#define sz(a) int((a).size())
#define tr(c,i) for(typeof(c).begin() i = c.begin(); i != c.end(); i++)
#define present(c,x) (c.find(x) != c.end())
#define cpresent(c,x) (find(all(c,x) != c.end())

typedef pair< int,int > ii;
typedef vector<int> vi;
typedef long long ll;
typedef vector< vector<int> > vvi;
int INF = 1e9;

void calculate() {

}
int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int T;
    cin >> T;
    while(T--){
        int n;
        cin >> n;
        vi data(n);
        REP(i,0,n){
            cin >> data[i];
        }
        int c = count(all(data),data[0]);
        // if everything is same
        if(c == n) {
            cout << 0 << endl;
            continue;
        }
        // 1 2 3 1 2 3 1
        int ans = INF;
        if (data[0] == data[n-1]) {
            ans = c - 1;
        }

        REP(i,1,n){
            c = count(all(data),data[i]);
            if (c == 1) {
                ans = min(ans,c);
            } else {
                ans = min(ans,c+1);
            }
            if (ans==1) break;
        }
        cout << ans << endl;
    }
}


#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<cmath>
#include<numeric>
#include<set>
#include<assert.h>
#include<queue>
#include<stack>
#include<unordered_set>

using namespace std;

#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
    *this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "

#define REP(i,a,b) for(int i=a; i<b;++i)
#define endl "\n"
#define F first
#define S second
#define MP make_pair
#define PB push_back
#define all(a) a.begin(),a.end()
#define sz(a) int((a).size())
#define tr(c,i) for(typeof(c).begin() i = c.begin(); i != c.end(); i++)
#define present(c,x) (c.find(x) != c.end())
#define cpresent(c,x) (find(all(c,x) != c.end())

typedef pair< int,int > ii;
typedef vector<int> vi;
typedef long long ll;
typedef vector< vector<int> > vvi;
int INF = 1e9;

void calculate() {

}
int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int T;
    cin >> T;
    while(T--){
        int n;
        cin >> n;
        vi data;
        int d,p;
        cin >> d;
        data.PB(d);
        p=d;
        REP(i,1,n){
            cin >> d;
            if(d != p) {
                data.PB(d);
                p=d;
            }
        }
        n = data.size();
        debug() << imie(data);
        int c = count(all(data),data[0]);
        // if everything is same
        if(c == n) {
            cout << 0 << endl;
            continue;
        }
        int ans = INF;
        if (data[0] == data[n-1]) {
            ans = c - 1;
        }
        REP(i,0,n){
            c = count(all(data),data[i]);
            if (c == 1) {
                if(i==0 or i == n-1) {
                    ans = c;
                    break;
                } else {
                    ans = min(ans,c+1);
                }

            } else {
                if(data[i] == data[0] or data[i] == data[n-1])
                {
                    c--;
                }
                ans = min(ans,c+1);
            }
            if (ans==1) break;
        }
        cout << ans << endl;
    }
}


#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<cmath>
#include<numeric>
#include<set>
#include<assert.h>
#include<queue>
#include<stack>
#include<unordered_set>

using namespace std;

#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
    *this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "

#define REP(i,a,b) for(int i=a; i<b;++i)
#define endl "\n"
#define F first
#define S second
#define MP make_pair
#define PB push_back
#define all(a) a.begin(),a.end()
#define sz(a) int((a).size())
#define tr(c,i) for(typeof(c).begin() i = c.begin(); i != c.end(); i++)
#define present(c,x) (c.find(x) != c.end())
#define cpresent(c,x) (find(all(c,x) != c.end())

typedef pair< int,int > ii;
typedef vector<int> vi;
typedef long long ll;
typedef vector< vector<int> > vvi;
int INF = 1e9;

void calculate() {

}
int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int T;
    cin >> T;
    while(T--){
        int n;
        cin >> n;
        vi data;
        int d,p;
        cin >> d;
        data.PB(d);
        p=d;
        REP(i,1,n){
            cin >> d;
            if(d != p) {
                data.PB(d);
                p=d;
            }
        }
        n = data.size();
        //debug() << imie(data);
        int c = count(all(data),data[0]);
        // if everything is same
        if(c == n) {
            cout << 0 << endl;
            continue;
        }
        int ans = INF;
        if (data[0] == data[n-1]) {
            ans = c - 1;
        }
        REP(i,0,n){
            c = count(all(data),data[i]);
            if (c == 1) {
                ans = c;
                break;
            } else {
                if(data[i] == data[0] or data[i] == data[n-1]) c--;
                ans = min(ans,c+1);
            }
            if (ans==1) break;
        }
        cout << ans << endl;
    }
}


#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<cmath>
#include<numeric>
#include<set>
#include<assert.h>
#include<queue>
#include<stack>
#include<unordered_set>

using namespace std;

#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
    *this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "

#define REP(i,a,b) for(int i=a; i<b;++i)
#define endl "\n"
#define F first
#define S second
#define MP make_pair
#define PB push_back
#define all(a) a.begin(),a.end()
#define sz(a) int((a).size())
#define tr(c,i) for(typeof(c).begin() i = c.begin(); i != c.end(); i++)
#define present(c,x) (c.find(x) != c.end())
#define cpresent(c,x) (find(all(c,x) != c.end())

typedef pair< int,int > ii;
typedef vector<int> vi;
typedef long long ll;
typedef vector< vector<int> > vvi;
int INF = 1e9;

void calculate() {

}
int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int T;
    cin >> T;
    while(T--){
        int n;
        cin >> n;
        vi data;
        int d,p;
        cin >> d;
        data.PB(d);
        p=d;
        REP(i,1,n){
            cin >> d;
            if(d != p) {
                data.PB(d);
                p=d;
            }
        }
        n = data.size();
        debug() << imie(data);
        int c = count(all(data),data[0]);
        // if everything is same
        if(c == n) {
            cout << 0 << endl;
            continue;
        }
        int ans = INF;
        if (data[0] == data[n-1]) {
            ans = c - 1;
        }
        REP(i,0,n){
            c = count(all(data),data[i]);
            if (c == 1) {
                if(i==0 or i == n-1) {
                    ans = c;
                    break;
                } else {
                    ans = min(ans,c+1);
                    break;
                }

            } else {
                if(data[i] == data[0] or data[i] == data[n-1])
                {
                    c--;
                }
                ans = min(ans,c+1);
            }
            if (ans==1) break;
        }
        cout << ans << endl;
    }
}


#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<cmath>
#include<numeric>
#include<set>
#include<assert.h>
#include<queue>
#include<stack>
#include<unordered_set>

using namespace std;

#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
    *this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "

#define REP(i,a,b) for(int i=a; i<b;++i)
#define endl "\n"
#define F first
#define S second
#define MP make_pair
#define PB push_back
#define all(a) a.begin(),a.end()
#define sz(a) int((a).size())
#define tr(c,i) for(typeof(c).begin() i = c.begin(); i != c.end(); i++)
#define present(c,x) (c.find(x) != c.end())
#define cpresent(c,x) (find(all(c,x) != c.end())

typedef pair< int,int > ii;
typedef vector<int> vi;
typedef long long ll;
typedef vector< vector<int> > vvi;
int INF = 1e9;

void calculate() {

}
int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int T;
    cin >> T;
    while(T--){
        int n;
        cin >> n;
        vi data;
        int d,p;
        cin >> d;
        data.PB(d);
        p=d;
        REP(i,1,n){
            cin >> d;
            if(d != p) {
                data.PB(d);
                p=d;
            }
        }
        n = data.size();
        //debug() << imie(data);
        int c = count(all(data),data[0]);
        // if everything is same
        if(c == n) {
            cout << 0 << endl;
            continue;
        }
        int ans = INF;
        if (data[0] == data[n-1]) {
            ans = c - 1;
        }
        REP(i,1,n){
            c = count(all(data),data[i]);
            if (c == 1) {
                ans = c;
                break;
            } else {
                if(data[i] == data[0] or data[i] == data[n-1]) c--;
                ans = min(ans,c+1);
            }
            if (ans==1) break;
        }
        cout << ans << endl;
    }
}


#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<cmath>
#include<numeric>
#include<set>
#include<assert.h>
#include<queue>
#include<stack>
#include<unordered_set>

using namespace std;

#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
    *this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "

#define REP(i,a,b) for(int i=a; i<b;++i)
#define endl "\n"
#define F first
#define S second
#define MP make_pair
#define PB push_back
#define all(a) a.begin(),a.end()
#define sz(a) int((a).size())
#define tr(c,i) for(typeof(c).begin() i = c.begin(); i != c.end(); i++)
#define present(c,x) (c.find(x) != c.end())
#define cpresent(c,x) (find(all(c,x) != c.end())

typedef pair< int,int > ii;
typedef vector<int> vi;
typedef long long ll;
typedef vector< vector<int> > vvi;
int INF = 1e9;

void calculate() {

}
int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int T;
    cin >> T;
    while(T--){
        int n;
        cin >> n;
        vi data(n);
        REP(i,0,n){
            cin >> data[i];
        }
        n = data.size();
        //debug() << imie(data);
        bool inc;
        int ans = INF;
        REP(i,0,n){
            int current = data[i];
            inc = true;
            int counter = 0;
            REP(j,0,n){
                int check = data[j];
                if(check != current){
                    if(inc) {
                        counter++;
                        inc = false;
                        //cout << "data not match: " << check << " current : " << current << endl;
                    }

                } else {
                    //cout << "data match: " << check << " current : " << current << endl;
                    inc = true;
                }
            }
            //cout << counter << endl;
            ans = min(ans,counter);
        }
        //debug() << imie(ans);

        // int c = count(all(data),data[0]);
        // // if everything is same
        // if(c == n) {
        //     cout << 0 << endl;
        //     continue;
        // }
        // int ans = INF;
        // if (data[0] == data[n-1]) {
        //     ans = c - 1;
        // }
        // REP(i,0,n){
        //     // c = count(all(data),data[i]);
        //     if (c == 1) {
        //         if(i==0 or i == n-1) {
        //             ans = c;
        //             break;
        //         } else {
        //             ans = 2;
        //         }

        //     } else {
        //         if(data[i] == data[0] or data[i] == data[n-1])
        //         {
        //             c--;
        //         }
        //         ans = min(ans,c+1);
        //     }
        //     if (ans==1) break;
        // }
        cout << ans << endl;
    }
}


#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<cmath>
#include<numeric>
#include<set>
#include<assert.h>
#include<queue>
#include<stack>
#include<unordered_set>

using namespace std;

#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
    *this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "

#define REP(i,a,b) for(int i=a; i<b;++i)
#define endl "\n"
#define F first
#define S second
#define MP make_pair
#define PB push_back
#define all(a) a.begin(),a.end()
#define sz(a) int((a).size())
#define tr(c,i) for(typeof(c).begin() i = c.begin(); i != c.end(); i++)
#define present(c,x) (c.find(x) != c.end())
#define cpresent(c,x) (find(all(c,x) != c.end())

typedef pair< int,int > ii;
typedef vector<int> vi;
typedef long long ll;
typedef vector< vector<int> > vvi;
int INF = 1e9;

void calculate() {

}
int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int T;
    cin >> T;
    while(T--){
        int n;
        cin >> n;
        vi data(n);
        REP(i,0,n){
            cin >> data[i];
        }
        n = data.size();
        //debug() << imie(data);
        bool inc;
        int ans = INF;
        REP(i,0,n){
            int current = data[i];
            inc = true;
            int counter = 0;
            REP(j,0,n){
                int check = data[j];
                if(check != current){
                    if(inc) {
                        counter++;
                        inc = false;
                        //cout << "data not match: " << check << " current : " << current << endl;
                    }

                } else {
                    //cout << "data match: " << check << " current : " << current << endl;
                    inc = true;
                }
            }
            //cout << counter << endl;
            ans = min(ans,counter);
            if (ans <= 1) break;
        }
        //debug() << imie(ans);

        // int c = count(all(data),data[0]);
        // // if everything is same
        // if(c == n) {
        //     cout << 0 << endl;
        //     continue;
        // }
        // int ans = INF;
        // if (data[0] == data[n-1]) {
        //     ans = c - 1;
        // }
        // REP(i,0,n){
        //     // c = count(all(data),data[i]);
        //     if (c == 1) {
        //         if(i==0 or i == n-1) {
        //             ans = c;
        //             break;
        //         } else {
        //             ans = 2;
        //         }

        //     } else {
        //         if(data[i] == data[0] or data[i] == data[n-1])
        //         {
        //             c--;
        //         }
        //         ans = min(ans,c+1);
        //     }
        //     if (ans==1) break;
        // }
        cout << ans << 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 < 200; 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 < 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;
    }
}