#include <bits/stdc++.h>
using namespace std;
const double pi = acos(-1);
long long GCD(long long a, long long b) { return b == 0 ? a : GCD(b, a % b); }
int main() {
  int t;
  cin >> t;
  while (t--) {
    int n;
    cin >> n;
    vector<int> v;
    for (int i = 0; i < n; i++) {
      int tt;
      cin >> tt;
      if (v.size() == 0)
        v.push_back(tt);
      else {
        if (tt * v.back() < 0) {
          v.push_back(tt);
          continue;
        }
        int f = 0;
        while (v.back() * tt > 0 && tt > v.back()) {
          v.pop_back();
          f = 1;
        }
        if (f) {
          v.push_back(tt);
        }
      }
    }
    long long ans = 0;
    for (int i = 0; i < v.size(); i++) {
      ans += v[i];
    }
    cout << ans << endl;
  }
  return 0;
}
