#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 100;
long long a[maxn], tree[maxn];
long long n;
void solve() {
  long long ans = -0x3f3f3f3f;
  long long sum = a[n];
  ans = max(ans, sum);
  for (long long i = n - 1; i >= 1; i--) {
    sum += a[i];
    ans = max(ans, sum);
  }
  cout << ans << endl;
}
int main(void) {
  cin.tie(0);
  std::ios::sync_with_stdio(false);
  long long t;
  cin >> t;
  while (t--) {
    cin >> n;
    for (long long i = 1; i <= n; i++) cin >> a[i];
    solve();
  }
  return 0;
}
