#include <bits/stdc++.h>
using namespace std;
// Function to compute GCD of a list of numbers
int compute_gcd_list(const vector<int>& nums) {
if (nums.empty()) return 0; // Undefined, but handled appropriately
int result = nums[0];
for(int i = 1; i < nums.size(); ++i) {
result = gcd(result, nums[i]);
if(result == 1) break; // Early termination
}
return result;
}
int main(){
ios::sync_with_stdio(false);
cin.tie(0);
int T;
cin >> T;
while(T--){
int N;
cin >> N;
vector<int> A(N);
for(auto &x : A) cin >> x;
// Precompute GCD for all subsets
// There are 2^N subsets
int total_masks = 1 << N;
vector<int> subset_gcd(total_masks, 0);
for(int mask = 1; mask < total_masks; mask++) {
// Find the least significant set bit
int lsb = mask & (-mask);
int pos = log2(lsb);
// Remove the least significant set bit to get the previous subset
int prev_mask = mask ^ lsb;
if(prev_mask == 0){
// Only one element in the subset
subset_gcd[mask] = A[pos];
}
else{
// GCD of the current element and the GCD of the previous subset
subset_gcd[mask] = gcd(A[pos], subset_gcd[prev_mask]);
// Early termination if GCD becomes 1
if(subset_gcd[mask] == 1){
// No need to compute further as GCD cannot be lower than 1
// But since mask includes more elements, it will still be processed
}
}
}
// Determine the number of elements in Subset 1 (Odd positions)
int m = (N + 1) / 2;
int max_sum = 0;
// Iterate through all possible masks with exactly m bits set
// Utilize bitmask enumeration and the precomputed GCDs
for(int mask = 0; mask < total_masks; mask++) {
if(__builtin_popcount(mask) != m) continue;
// GCD for Subset 1 (Odd indices)
int gcd1 = subset_gcd[mask];
// GCD for Subset 2 (Even indices)
int complement_mask = ((1 << N) - 1) ^ mask;
int gcd2;
if(complement_mask == 0){
gcd2 = 0; // No elements in Subset 2
}
else{
gcd2 = subset_gcd[complement_mask];
}
// Calculate the sum
int current_sum = gcd1 + gcd2;
// Update the maximum sum
if(current_sum > max_sum){
max_sum = current_sum;
}
}
cout << max_sum << "\n";
}
}