## GUPTA MECHANICAL

IN THIS WEBSITE I CAN TELL ALL ABOUT TECH. TIPS AND TRICKS APP REVIEWS AND UNBOXINGS ALSO TECH. NEWS .............

## [Solution] Equal After And CodeChef Solution | CodeChef Problem Solution 2022

You are given an array $A=\left[{A}_{1},{A}_{2},\dots ,{A}_{N}\right]$, consisting of $N$ integers. In one move, you can take two adjacent numbers ${A}_{i}$ and ${A}_{i+1}$, delete them, and then insert the number ${A}_{i}\wedge {A}_{i+1}$ at the deleted position. Here, $\wedge$ denotes bitwise AND. Note that after this operation, the length of the array decreases by one.

Formally, as long as $|A|>1$ (where $|A|$ denotes the current length of $A$), you can pick an index $1\le i<|A|$ and transform $A$ into $\left[{A}_{1},{A}_{2},\dots ,{A}_{i-1},{A}_{i}\wedge {A}_{i+1},{A}_{i+2},\dots ,{A}_{|A|}\right]$.

Find the minimum number of moves required to make all numbers in the resulting array equal.

### Input Format

• The first line of input contains an integer $T$ — the number of test cases you need to solve.

• The first line of each test case contains one integer $N$, the size of the array.
• The second line of each test case contains $N$ space-separated integers ${A}_{1},\dots ,{A}_{N}$ — the elements of the array $A$.

### Output Format

For each test case, output on a new line the minimum number of moves required to make all numbers equal.

### Constraints

• $1\le T\le {10}^{6}$
• $2\le N\le {10}^{6}$
• Sum of $N$ over all test cases is at most ${10}^{6}$.
• $0\le {A}_{i}<{2}^{30}$

• $0\le {A}_{i}\le 255$
• Sum of $N$ over all test cases is at most $255$.
• Sum of $N$ over all test cases is at most $2000$.