#include <iostream>
#include <vector>
#include <unordered_map>
#include <algorithm>
using namespace std;
// Hàm Hash tùy chỉnh để lưu trạng thái mảng vào unordered_map
struct VectorHasher {
size_t operator()(const vector<long long>& V) const {
size_t hash = V.size();
for (long long i : V) {
hash ^= i + 0x9e3779b9 + (hash << 6) + (hash >> 2);
}
return hash;
}
};
int n;
unordered_map<vector<long long>, int, VectorHasher> memo;
int dfs(vector<long long>& a) {
// Điều kiện dừng: Tất cả phần tử đã về 0
bool all_zero = true;
for (long long x : a) {
if (x != 0) {
all_zero = false;
break;
}
}
if (all_zero) return 0;
// Trả về kết quả nếu đã tính toán
if (memo.count(a)) return memo[a];
int ans = 1e9;
// Duyệt qua tất cả các đoạn con dài nhất (maximal intervals) có cùng tính chẵn lẻ
for (int i = 0; i < n; ) {
int j = i;
int parity = a[i] & 1;
bool has_nonzero = false;
// Mở rộng đoạn [i, j) xa nhất có thể
while (j < n && (a[j] & 1) == parity) {
if (a[j] != 0) has_nonzero = true;
j++;
}
// Chỉ chia đôi nếu đoạn này có ít nhất 1 phần tử khác 0
if (has_nonzero) {
vector<long long> nxt = a;
for (int k = i; k < j; ++k) {
nxt[k] >>= 1;
}
// Đệ quy tìm số bước tối thiểu
ans = min(ans, 1 + dfs(nxt));
}
// Chuyển sang đoạn tiếp theo
i = j;
}
return memo[a] = ans;
}
void solve() {
cin >> n;
vector<long long> a(n);
for (int i = 0; i < n; ++i) {
cin >> a[i];
}
// Reset bảng nhớ cho mỗi testcase
memo.clear();
cout << dfs(a) << "\n";
}
int main() {
// Tối ưu I/O
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int t;
if (cin >> t) {
while (t--) {
solve();
}
}
return 0;
}