#include <bits/stdc++.h>
const double Epsilon = 4.94065645841247E-324;
const long double PI = 3.14159265358979323846;
const long long int MOD = 1000000007;
using namespace std;
clock_t beg = clock();
int main() {
  int t = 1;
  cin >> t;
  int ti = 0;
  while (ti++ < t) {
    int n;
    cin >> n;
    long long arr[n];
    long long ans[n];
    memset((ans), 0, (sizeof(ans)));
    for (int i = 0; i < n; ++i) cin >> arr[i];
    long long neg = 0;
    for (int i = n - 1; i >= 0; --i) {
      if (arr[i] < 0)
        neg += -arr[i];
      else if (arr[i]) {
        long long prev = arr[i];
        ans[i] = max(0LL, arr[i] - neg);
        neg -= (prev - ans[i]);
      }
    }
    long long anssum = 0;
    for (int i = 0; i < n; ++i) anssum += ans[i];
    cout << anssum << "\n";
  }
  cerr << "\nExecution time: " << (clock() - beg) / 1000 << '\n';
  return 0;
}
