#include <bits/stdc++.h>
using namespace std;
int main() {
  long long int t, n;
  cin >> t;
  while (t--) {
    cin >> n;
    long long int a[n];
    for (long long int i = 0; i < n; i++) {
      cin >> a[i];
    }
    long long int max_so_far = a[n - 1];
    long long int curr = a[n - 1];
    for (long long int i = n - 2; i >= 0; i--) {
      max_so_far = max(curr, max_so_far);
      curr += a[i];
    }
    max_so_far = max(curr, max_so_far);
    cout << max_so_far << endl;
  }
  return 0;
}
