#include <iostream>
#include <vector>
using namespace std;
using i64 = long long;
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int tc;
cin >> tc;
while (tc--) {
int n;
cin >> n;
vector a(n, 0);
for (auto& i : a) {
cin >> i;
}
if (n == 1) {
cout << a.front() << '\n';
continue;
} else if (n == 2) {
cout << max(a.front() - a.back(), a.back() - a.front()) << '\n';
continue;
}
i64 sum = 0;
bool pos = false, neg = false;
for (auto& x : a) {
pos |= x > 0;
neg |= x < 0;
sum += abs(x);
}
// cerr << sum << '\n';
if (pos and neg) {
cout << sum << '\n';
continue;
}
if (count(a.begin(), a.end(), a.front()) == n) {
cout << (n - 2ll) * abs(a.front()) << '\n';
continue;
}
i64 ans = 0;
if (pos) {
for (int i = 0; i < n; i++) {
int x = a[i], y = a[(i + 1) % n];
if (x - y < 0) {
ans = max(ans, sum - x * 2);
}
}
} else {
for (int i = 0; i < n; i++) {
int x = a[i], y = a[(i + 1) % n];
if (x - y > 0) {
ans = max(ans, sum + x * 2);
}
}
}
cout << ans << '\n';
}
return 0;
}