#include<bits/stdc++.h>
#define endl '\n'
#define F first
#define S second
#define pb push_back
#define yes cout<<"YES\n"
#define no cout<<"NO\n"
#define all(x) x.begin(),x.end()
#define allr(x) x.rbegin(),x.rend()
#define error1(x) cerr<<#x<<" = "<<(x)<<endl
#define error2(a,b) cerr<<"("<<#a<<", "<<#b<<") = ("<<(a)<<", "<<(b)<<")\n";
#define coutall(v) for(auto &it: v) cout << it << " "; cout << endl;
using namespace std;
using ll = long long;
using ld = long double;
void solve() {
ll n;
cin >> n;
vector<ll> v(n);
for (int i = 0; i < n; i++) {
ll x; cin >> x;
v[i] = x;
}
vector<vector<map<pair<int, int>, int>>> dp((n / 2) + 2, vector<map<pair<int, int>, int>> (n + 1));
auto rec = [&](int i, int odd, int even, ll gcd1, ll gcd2, auto&& self) -> int {
if(i == n) return gcd1 + gcd2;
auto it = dp[odd][i].find(make_pair(gcd1, gcd2));
if(it != dp[odd][i].end()) return it->S;
int mx = 0;
if(odd > 0) {
if(gcd1 == -1) mx = max(mx, self(i + 1, odd - 1, even, v[i], gcd2, self));
else mx = max(mx, self(i + 1, odd - 1, even, __gcd(gcd1, v[i]), gcd2, self));
}
if(even > 0) {
if(gcd2 == -1) mx = max(mx, self(i + 1, odd, even - 1, gcd1, v[i], self));
else mx = max(mx, self(i + 1, odd, even - 1, gcd1, __gcd(v[i], gcd2), self));
}
return dp[odd][i][{gcd1, gcd2}] = mx;
};
cout << rec(0, (n + 1) >> 1, n >> 1, -1, -1, rec) << endl;
return;
}
signed main() {
ios::sync_with_stdio(false); cin.tie(0);
int tc = 1;
cin >> tc;
for (int t = 1; t <= tc; t++) {
// cout << "Case " << t << ": ";
solve();
}
return 0;
}