#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  cin >> t;
  while (t--) {
    int n;
    cin >> n;
    int num;
    long long sum = 0;
    int pn = -1;
    vector<long long> v;
    for (int i = 0; i < n; i++) {
      cin >> num;
      if (!i)
        sum = num;
      else if ((pn && num < 0) || (pn == 0 && num > 0))
        sum += num;
      else {
        v.push_back(sum);
        sum = num;
      }
      if (num > 0)
        pn = 1;
      else
        pn = 0;
    }
    v.push_back(sum);
    long long ans = v[0];
    for (int i = 1; i < v.size(); i++) {
      ans = max(ans, v[i]);
    }
    cout << ans << endl;
  }
  return 0;
}
