#include <bits/stdc++.h>
using namespace std;
long long a[100001];
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int T;
  cin >> T;
  while (T--) {
    int n;
    cin >> n;
    long long ans = 0;
    long long p = 0;
    for (int i = 1; i <= n; i++) {
      cin >> a[i];
      a[i] += p;
      p = 0;
      if (a[i] > 0) {
        p += a[i];
      }
    }
    for (int i = 1; i <= n; i++) {
      if (a[i] < 0) ans -= a[i];
    }
    cout << ans << '\n';
  }
}
