#include <bits/stdc++.h>
using namespace std;
const int maxn = 10000000;
bool isprime[maxn + 1];
int sumdigit(long long n) {
  int sum = 0;
  while (n) {
    sum += n % 10;
    n /= 10;
  }
  return sum;
}
int main(void) {
  int t;
  int tt = 1;
  cin >> t;
  while (t--) {
    int n;
    cin >> n;
    long long arr[n];
    for (int i = 0; i < n; i++) {
      cin >> arr[i];
    }
    long long cur = 0;
    for (int i = 0; i < n; i++) {
      if (arr[i] > 0) {
        cur += arr[i];
        arr[i] = 0;
      } else if (arr[i] < 0 && cur > 0) {
        long long tmp = llabs(arr[i]);
        long long tmp2 = cur;
        cur -= min(tmp2, tmp);
        arr[i] += min(tmp2, tmp);
      }
    }
    cout << arr[n - 1] + cur << endl;
  }
}
