#include <bits/stdc++.h>
using namespace std;
// Speed
#define fast_io ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)
// Typedefs
#define int long long
#define pb push_back
#define ff first
#define ss second
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) ((int)(x).size())
#define endl '\n'
#define yes cout << "YES\n"
#define no cout << "NO\n"
// Loops
#define rep(i,a,b) for(int i=a;i<b;++i)
#define per(i,a,b) for(int i=b-1;i>=a;--i)
#define each(x, a) for (auto& x : a)
// Consts
const int INF = 1e18;
const int MOD = 1e9+7;
const int N = 2e5 + 5;
// Math
int gcd(int a, int b) { return b == 0 ? a : gcd(b, a % b); }
int lcm(int a, int b) { return (a / gcd(a, b)) * b; }
int power(int a, int b, int m = MOD) {
int res = 1;
while (b > 0) {
if (b & 1) res = res * a % m;
a = a * a % m;
b >>= 1;
}
return res;
}
int modinv(int a, int m = MOD) {
return power(a, m - 2, m);
}
// Logic
void solve() {
int n;
cin >> n;
map<int, int> counts;
int total_sum = 0;
rep(i, 0, n) {
int val;
cin >> val;
counts[val]++;
total_sum += val;
}
vector<pair<int, int>> sorted_counts;
each(p, counts) {
sorted_counts.pb(p);
}
multiset<int> kept_singles;
multiset<int> pruned_singles;
int pruned_sum = 0;
vector<int> initial_singles;
each(p, counts) {
if (p.ss % 2 != 0) initial_singles.pb(p.ff);
}
sort(rall(initial_singles));
rep(i, 0, sz(initial_singles)) {
if (i < 2) {
kept_singles.insert(initial_singles[i]);
} else {
pruned_singles.insert(initial_singles[i]);
pruned_sum += initial_singles[i];
}
}
per(i, 0, sz(sorted_counts)) {
int s_max_candidate = sorted_counts[i].ff;
int p_candidate = total_sum - pruned_sum;
if (p_candidate > 2 * s_max_candidate) {
cout << p_candidate << endl;
return;
}
int L = sorted_counts[i].ff;
int C = sorted_counts[i].ss;
total_sum -= L * C;
if (C % 2 != 0) {
auto it_kept = kept_singles.find(L);
if (it_kept != kept_singles.end()) {
kept_singles.erase(it_kept);
} else {
auto it_pruned = pruned_singles.find(L);
pruned_sum -= *it_pruned;
pruned_singles.erase(it_pruned);
}
if (sz(kept_singles) < 2 && !pruned_singles.empty()) {
int to_move = *pruned_singles.rbegin();
pruned_sum -= to_move;
pruned_singles.erase(prev(pruned_singles.end()));
kept_singles.insert(to_move);
}
}
}
cout << 0 << endl;
}
// Main
int32_t main() {
fast_io;
int t = 1;
cin >> t;
while (t--) {
solve();
}
return 0;
}