#include using ll = long long; using namespace std; #define rep(i, s, t) for (ll i = s; i < (ll)(t); i++) #define rrep(i, s, t) for (ll i = (ll)(t) - 1; i >= (ll)(s); i--) #define all(x) begin(x), end(x) #define rall(x) rbegin(x), rend(x) template bool chmin(T& x, T y) { return x > y ? (x = y, true) : false; } template bool chmax(T& x, T y) { return x < y ? (x = y, true) : false; } struct io_setup { io_setup() { ios::sync_with_stdio(false); std::cin.tie(nullptr); cout << fixed << setprecision(15); } } io_setup; #include void solve() { int n; cin>>n; vector a(n); rep(i,0,n) cin>>a[i]; vector dp(6,0); rep(i,0,n){ vector ndp(6,0); ndp[0]=dp[0]+a[i]; ndp[1]=dp[1]-a[i]; ndp[2]=max({dp[0],dp[1],dp[2]})+a[i]; ndp[3]=max({dp[0],dp[1],dp[3]})-a[i]; ndp[4]=max({dp[2],dp[3],dp[4]})+a[i]; ndp[5]=max({dp[2],dp[3],dp[5]})-a[i]; swap(dp,ndp); } cout<> t; while (t--) solve(); }