#include <bits/stdc++.h>
using namespace std;
const long long mod = 1e9 + 7;
const long long maxn = 2e5 + 5;
long long f() {
  long long n;
  cin >> n;
  vector<long long> v;
  for (long long i = 0; i < n; ++i) {
    long long x;
    cin >> x;
    v.emplace_back(x);
  }
  bool ispos = 0;
  if (v[0] > 0) ispos = 1;
  vector<long long> curr;
  long long ans = 0;
  for (long long i = 0; i < n; ++i) {
    curr.emplace_back(v[i]);
    if (i + 1 < n and v[i + 1] * v[i] < 0) {
      sort(curr.begin(), curr.end());
      ans += curr.back();
      curr.clear();
      if (v[i + 1] > 0)
        ispos = 1;
      else
        ispos = 0;
    }
  }
  sort(curr.begin(), curr.end());
  ans += curr.back();
  return ans;
}
int32_t main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  long long t;
  cin >> t;
  while (t--) {
    cout << f() << '\n';
    ;
  }
  return 0;
}
