#include <bits/stdc++.h>
using namespace std;
#define ll long long
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0), cout.tie(0);
int t = 1;
cin >> t;
while (t--) {
int n;
cin >> n;
vector<ll> x(n);
ll sum = 0, mx = 0;
for (int i = 0; i < n; i++) {
cin >> x[i];
sum += x[i];
mx = max(mx, x[i]);
}
if (n == 2) {
cout << max(sum, abs(x[0] - x[1]) * 2) << '\n';
continue;
}
if (n == 3) {
cout << max({sum, max(x[0], x[2]) * 3,abs(x[0]-x[1])*3,abs(x[2]-x[1])*3}) << '\n';
continue;
}
ll ans = mx * n;
cout << ans << '\n';
}
}
1478B - Nezzar and Lucky Number | 228A - Is your horseshoe on the other hoof |
122A - Lucky Division | 1611C - Polycarp Recovers the Permutation |
432A - Choosing Teams | 758A - Holiday Of Equality |
1650C - Weight of the System of Nested Segments | 1097A - Gennady and a Card Game |
248A - Cupboards | 1641A - Great Sequence |
1537A - Arithmetic Array | 1370A - Maximum GCD |
149A - Business trip | 34A - Reconnaissance 2 |
59A - Word | 462B - Appleman and Card Game |
1560C - Infinity Table | 1605C - Dominant Character |
1399A - Remove Smallest | 208A - Dubstep |
1581A - CQXYM Count Permutations | 337A - Puzzles |
495A - Digital Counter | 796A - Buying A House |
67A - Partial Teacher | 116A - Tram |
1472B - Fair Division | 1281C - Cut and Paste |
141A - Amusing Joke | 112A - Petya and Strings |