#include <bits/stdc++.h>
using namespace std;
int sign(long long x) { return (x > 0 ? 1 : -1); }
void solve() {
  int n;
  cin >> n;
  long long x;
  vector<long long> v;
  for (int i = 0; i < n; ++i) {
    cin >> x;
    if (v.empty())
      v.push_back(x);
    else {
      if (sign(x) == sign(v.back())) {
        if (x > v.back()) {
          v.pop_back();
          v.push_back(x);
        }
      } else {
        v.push_back(x);
      }
    }
  }
  cout << accumulate(v.begin(), v.end(), 0LL) << "\n";
}
int main() {
  int t;
  cin >> t;
  while (t--) solve();
  return 0;
}
