#include <bits/stdc++.h>
using namespace std;
int main(){
ios::sync_with_stdio(false);
cin.tie(0);
int t;
cin >> t;
while(t--){
int n;
cin >> n;
vector<unsigned long long> a(n);
int Z =0;
vector<unsigned long long> b;
for(auto &x: a){
cin >> x;
if(x ==0) Z++;
else b.push_back(x);
}
// DP: map from OR to max size
unordered_map<unsigned long long, int> dp;
dp[0] =0;
for(auto x: b){
unordered_map<unsigned long long, int> tmp;
for(auto &[or_key, s]: dp){
unsigned long long new_or = or_key | x;
int new_size = s +1;
auto it = tmp.find(new_or);
if(it == tmp.end() || it->second < new_size){
tmp[new_or] = new_size;
}
}
for(auto &[k, v]: tmp){
auto it = dp.find(k);
if(it == dp.end() || it->second < v){
dp[k] = v;
}
}
}
// Now find the maximum value
long long max_val = (long long)Z; // empty subset
for(auto &[k, s]: dp){
// Calculate popcount
int cnt = __builtin_popcountll(k);
long long val = (long long)Z + (long long)s - (long long)cnt;
if(val > max_val){
max_val = val;
}
}
cout << max_val << "\n";
}
}
I2luY2x1ZGUgPGJpdHMvc3RkYysrLmg+CnVzaW5nIG5hbWVzcGFjZSBzdGQ7CgppbnQgbWFpbigpewogICAgaW9zOjpzeW5jX3dpdGhfc3RkaW8oZmFsc2UpOwogICAgY2luLnRpZSgwKTsKICAgIGludCB0OwogICAgY2luID4+IHQ7CiAgICB3aGlsZSh0LS0pewogICAgICAgIGludCBuOwogICAgICAgIGNpbiA+PiBuOwogICAgICAgIHZlY3Rvcjx1bnNpZ25lZCBsb25nIGxvbmc+IGEobik7CiAgICAgICAgaW50IFogPTA7CiAgICAgICAgdmVjdG9yPHVuc2lnbmVkIGxvbmcgbG9uZz4gYjsKICAgICAgICBmb3IoYXV0byAmeDogYSl7CiAgICAgICAgICAgIGNpbiA+PiB4OwogICAgICAgICAgICBpZih4ID09MCkgWisrOwogICAgICAgICAgICBlbHNlIGIucHVzaF9iYWNrKHgpOwogICAgICAgIH0KICAgICAgICAvLyBEUDogbWFwIGZyb20gT1IgdG8gbWF4IHNpemUKICAgICAgICB1bm9yZGVyZWRfbWFwPHVuc2lnbmVkIGxvbmcgbG9uZywgaW50PiBkcDsKICAgICAgICBkcFswXSA9MDsKICAgICAgICBmb3IoYXV0byB4OiBiKXsKICAgICAgICAgICAgdW5vcmRlcmVkX21hcDx1bnNpZ25lZCBsb25nIGxvbmcsIGludD4gdG1wOwogICAgICAgICAgICBmb3IoYXV0byAmW29yX2tleSwgc106IGRwKXsKICAgICAgICAgICAgICAgIHVuc2lnbmVkIGxvbmcgbG9uZyBuZXdfb3IgPSBvcl9rZXkgfCB4OwogICAgICAgICAgICAgICAgaW50IG5ld19zaXplID0gcyArMTsKICAgICAgICAgICAgICAgIGF1dG8gaXQgPSB0bXAuZmluZChuZXdfb3IpOwogICAgICAgICAgICAgICAgaWYoaXQgPT0gdG1wLmVuZCgpIHx8IGl0LT5zZWNvbmQgPCBuZXdfc2l6ZSl7CiAgICAgICAgICAgICAgICAgICAgdG1wW25ld19vcl0gPSBuZXdfc2l6ZTsKICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgfQogICAgICAgICAgICBmb3IoYXV0byAmW2ssIHZdOiB0bXApewogICAgICAgICAgICAgICAgYXV0byBpdCA9IGRwLmZpbmQoayk7CiAgICAgICAgICAgICAgICBpZihpdCA9PSBkcC5lbmQoKSB8fCBpdC0+c2Vjb25kIDwgdil7CiAgICAgICAgICAgICAgICAgICAgZHBba10gPSB2OwogICAgICAgICAgICAgICAgfQogICAgICAgICAgICB9CiAgICAgICAgfQogICAgICAgIC8vIE5vdyBmaW5kIHRoZSBtYXhpbXVtIHZhbHVlCiAgICAgICAgbG9uZyBsb25nIG1heF92YWwgPSAobG9uZyBsb25nKVo7IC8vIGVtcHR5IHN1YnNldAogICAgICAgIGZvcihhdXRvICZbaywgc106IGRwKXsKICAgICAgICAgICAgLy8gQ2FsY3VsYXRlIHBvcGNvdW50CiAgICAgICAgICAgIGludCBjbnQgPSBfX2J1aWx0aW5fcG9wY291bnRsbChrKTsKICAgICAgICAgICAgbG9uZyBsb25nIHZhbCA9IChsb25nIGxvbmcpWiArIChsb25nIGxvbmcpcyAtIChsb25nIGxvbmcpY250OwogICAgICAgICAgICBpZih2YWwgPiBtYXhfdmFsKXsKICAgICAgICAgICAgICAgIG1heF92YWwgPSB2YWw7CiAgICAgICAgICAgIH0KICAgICAgICB9CiAgICAgICAgY291dCA8PCBtYXhfdmFsIDw8ICJcbiI7CiAgICB9Cn0K