#include using namespace std; #define ll long long #define mod 1000000007 #define INF 1e18 #define nl "\n" #define pb push_back #define eb emplace_back /*Note: emplace_back is faster than push_back*/ #define ppb pop_back #define mp make_pair #define ff first #define ss second #define PI 3.141592653589793238462 #define set_bits __builtin_popcountll #define sz(x) ((int)(x).size()) #define all(x) (x).begin(), (x).end() long long maxSubarraySum(vector &nums) { int n = nums.size(); long long mx = LONG_MIN; // maximum sum long long sum = 0; for (int i = 0; i < n; i++) { sum += nums[i]; if (sum > mx) { mx = sum; } if (sum < 0) { sum = 0; } } return mx; } void solve() { } int main() { // ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL); #ifndef ONLINE_JUDGE // freopen("input.txt", "r", stdin); // freopen("output.txt", "w", stdout); #endif ll t = 1; cin >> t; while (t--) { int n; cin >> n; vector a(n); for (int i = 0; i < n; i++) cin >> a[i]; cout << maxSubarraySum(a) << nl; } }