#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  cin >> t;
  while (t--) {
    int n;
    cin >> n;
    vector<int> v;
    bool all_negative = true;
    int test = -10000000;
    for (int i = 0; i < n; i++) {
      int temp;
      cin >> temp;
      test = max(test, temp);
      if (temp > 0) all_negative = false;
      v.push_back(temp);
    }
    if (all_negative == true) {
      sort(v.begin(), v.end());
      cout << v[n - 1] << endl;
    } else {
      v.push_back(0);
      long long int sum = v[0];
      int max_length = 0;
      int length = 1;
      long long int current_max = INT_MIN;
      for (int j = 0; j < n + 1; j++) {
        if (v[j] > 0 && v[j + 1] < 0) {
          sum += v[j + 1];
          current_max = max(current_max, sum);
        } else if (v[j] < 0 && v[j + 1] > 0) {
          sum += v[j + 1];
          if (length >= max_length) {
            length++;
            if (j == n) length--;
            max_length = max(max_length, length);
            current_max = max(current_max, sum);
          }
        } else {
          length = 0;
          sum = v[j + 1];
        }
      }
      cout << current_max << endl;
    }
    v.clear();
  }
}
