#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(false);
  int t;
  cin >> t;
  while (t--) {
    long long n, a[210000];
    cin >> n;
    int firstn = -1, firstp = -1;
    for (int i = 0; i < n; i++) {
      cin >> a[i];
      if (a[i] < 0 && firstn == -1) {
        firstn = i;
      }
      if (a[i] > 0 && firstp == -1) {
        firstp = i;
      }
    }
    if (firstn == -1) firstn = n;
    if (firstp == -1) firstp = n;
    vector<long long> neg;
    vector<long long> pos;
    set<long long> se;
    for (int i = firstn; i < n; i++) {
      if (a[i] > 0) {
        if (se.size() > 0) {
          set<long long>::iterator o = se.end();
          o--;
          neg.push_back(*o);
        }
        se.clear();
      } else {
        se.insert(a[i]);
      }
    }
    if (a[n - 1] < 0) {
      set<long long>::iterator o = se.end();
      o--;
      neg.push_back(*o);
    }
    se.clear();
    for (int i = firstp; i < n; i++) {
      if (a[i] < 0) {
        if (se.size() > 0) {
          set<long long>::iterator o = se.end();
          o--;
          pos.push_back(*o);
        }
        se.clear();
      } else {
        se.insert(a[i]);
      }
    }
    if (a[n - 1] > 0) {
      set<long long>::iterator o = se.end();
      o--;
      pos.push_back(*o);
    }
    long long s = 0;
    if (pos.size() >= neg.size()) {
      for (int i = 0; i < neg.size(); i++) {
        s += neg[i];
        s += pos[i];
      }
      if (pos.size() > neg.size()) {
        s += pos[neg.size()];
      }
    } else {
      for (int i = 0; i < pos.size(); i++) {
        s += pos[i];
        if (i != 0 && i != pos.size() - 1) {
          s += neg[i];
        }
      }
      if (pos.size() == 0)
        s += neg[0];
      else
        s += max(neg[0], neg[pos.size() - 1]);
    }
    cout << s << endl;
  }
  return 0;
}
