#include <bits/stdc++.h>
#pragma GCC optimize("O3")
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("unroll-loops")
using namespace std;
const long long M = (1e+9) + 7;
const long long N = 2e5 + 9;
long long gcd(long long a, long long b) {
  if (b == 0) return a;
  return gcd(b, a % b);
}
long long power(long long a, long long b) {
  long long res = 1;
  while (b > 0) {
    if (b & 1) res = (res * a);
    b = b >> 1;
    a = (a * a);
  }
  return res;
}
long long powerm(long long a, long long b) {
  long long res = 1;
  while (b > 0) {
    if (b & 1) res = (res * a) % M;
    b = b >> 1;
    a = (a * a) % M;
  }
  return res;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int tc;
  cin >> tc;
  while (tc--) {
    int n;
    cin >> n;
    int arr[n];
    for (int i = 0; i < n; i++) cin >> arr[i];
    int idx = 0;
    for (int i = 0; i < n; i++) {
      if (arr[i] > 0) {
        idx = i;
        break;
      }
    }
    long long sum = 0;
    for (int i = idx; i < n; i++) {
      sum = max(0ll, sum) + arr[i];
    }
    cout << sum << endl;
  }
  return 0;
}
