#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  cin >> t;
  while (t--) {
    int n;
    cin >> n;
    vector<long long> arr(n);
    multiset<long long> s1, s2;
    for (int i = 0; i < n; i++) {
      cin >> arr[i];
      if (arr[i] < 0)
        s1.insert(i);
      else
        s2.insert(i);
    }
    bool f = 0;
    for (auto i : s2) {
      while (arr[i]) {
        auto id = s1.lower_bound(i);
        if (id == s1.end()) {
          f = 1;
          break;
        }
        int mn = min(abs(arr[*id]), arr[i]);
        arr[i] -= mn;
        arr[*id] += mn;
        if (arr[*id] == 0) s1.erase(id);
      }
      if (f) break;
    }
    long long sum = 0;
    for (auto i : s2) sum += arr[i];
    cout << sum << "\n";
  }
}
