for _ in range(int(input())):
n = int(input())
a = [int(i) for i in input().split()]
l, r = None, None
for i in range(n-1):
if a[i] == a[i+1] :
if l == None : l = i
r = i
if l == r : print(0)
else : print(max(1, r-l-1))
/******************************************************/
/******************************************************/
/** BISMILLAHIR RAHMANIR RAHIM **/
/** Md.Faysal Ahamed - ER3N YAGER **/
/** Department of Computer Science and Engineering **/
/** Barisal University **/
/** It's time to Roar. **/
/******************************************************/
/******************************************************/
#include<bits/stdc++.h>
typedef long long int ll;
using namespace std;
#define gcd(a,b) __gcd(a,b)
#define lcm(a,b) (a*b)/gcd(a,b)
#define optimize() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
const ll N=1e9+7;
void solv()
{
ll n; cin>>n;
ll arr[n];
for(ll i=0; i<n; i++)cin>>arr[i];
ll mx=-1,mn=-1;
// ll First,Last;
for(ll i=0; i<n-1; i++)
{
if(arr[i]==arr[i+1])
{
if(mn==-1)mn=i+1;
mx=i+1;
}
}
if(mn==mx)cout<<0<<endl;
else cout<<max(mx-mn-1,1*1ll)<<endl;
}
int main()
{
optimize();
ll t; cin>>t;
while(t--)
{
solv();
}
}
/***************** ALHAMDULILLAH *****************/
461. Hamming Distance | 1748. Sum of Unique Elements |
897. Increasing Order Search Tree | 905. Sort Array By Parity |
1351. Count Negative Numbers in a Sorted Matrix | 617. Merge Two Binary Trees |
1450. Number of Students Doing Homework at a Given Time | 700. Search in a Binary Search Tree |
590. N-ary Tree Postorder Traversal | 589. N-ary Tree Preorder Traversal |
1299. Replace Elements with Greatest Element on Right Side | 1768. Merge Strings Alternately |
561. Array Partition I | 1374. Generate a String With Characters That Have Odd Counts |
1822. Sign of the Product of an Array | 1464. Maximum Product of Two Elements in an Array |
1323. Maximum 69 Number | 832. Flipping an Image |
1295. Find Numbers with Even Number of Digits | 1704. Determine if String Halves Are Alike |
1732. Find the Highest Altitude | 709. To Lower Case |
1688. Count of Matches in Tournament | 1684. Count the Number of Consistent Strings |
1588. Sum of All Odd Length Subarrays | 1662. Check If Two String Arrays are Equivalent |
1832. Check if the Sentence Is Pangram | 1678. Goal Parser Interpretation |
1389. Create Target Array in the Given Order | 1313. Decompress Run-Length Encoded List |