#include using namespace std; using ll = long long; const ll mod = 1e9 + 7; const int N = 200005; const ll INF = 0x3f3f3f3f3f3f3f3f; int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); int _; cin >> _; while (_--) { int n; cin >> n; vector a(n), sum(n); for (int i = 0; i < n; i++) cin >> a[i]; sum[0] = a[0]; for (int i = 1; i < n; i++) sum[i] = sum[i - 1] + a[i]; ll tot = sum[n - 1]; ll ans = 0; ll X = -INF, Y = -INF; if (sum[0] >= 0) X = 2 * sum[0]; else Y = -2 * sum[0]; for (int j = 1; j < n - 1; j++) { ll g = max(sum[j], -sum[j]); if (X != -INF) g = max(g, X - sum[j]); if (Y != -INF) g = max(g, sum[j] + Y); ll c1 = tot - sum[j]; ll c2 = g + llabs(c1); ans = max(ans, c2); if (sum[j] >= 0) X = max(X, 2 * sum[j]); else Y = max(Y, -2 * sum[j]); } cout << ans << "\n"; } return 0; }