#include <bits/stdc++.h>
int main(void) {
  int num;
  std::cin >> num;
  int size;
  int input;
  uint64_t output;
  int64_t pcapacity;
  for (int i = 0; i < num; i++) {
    output = 0;
    pcapacity = 0;
    std::cin >> size;
    for (int j = 0; j < size; j++) {
      std::cin >> input;
      if (input > 0) {
        pcapacity = pcapacity + input;
      }
      if (input < 0) {
        output = output + std::max((int64_t)0, abs(input) - pcapacity);
        pcapacity = pcapacity - std::min(pcapacity, (int64_t)abs(input));
      }
    }
    std::cout << output << "\n";
  }
}
