#include <bits/stdc++.h>
using namespace std;
void fastio() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
}
void solve() {
  long long n;
  cin >> n;
  vector<long long> v(n);
  for (int i = 0; i < n; i++) cin >> v[i];
  long long ans = -1e18;
  long long sm = 0;
  int i = 0;
  int l1 = 0;
  while (i < n and v[i] < 0) i++;
  if (i == n) sm = -1e18;
  long long cur = 0;
  bool pos = 1;
  for (; i < n; i++) {
    if (pos) {
      if (v[i] > 0) {
        cur = max(cur, v[i]);
      } else {
        sm += cur;
        cur = v[i];
        pos = 0;
        l1++;
      }
    } else {
      if (v[i] > 0) {
        sm += cur;
        cur = v[i];
        pos = 1;
        l1++;
      } else {
        cur = max(cur, v[i]);
      }
    }
  }
  sm += cur;
  i = 0;
  while (i < n and v[i] > 0) i++;
  long long sm1 = sm;
  sm = 0;
  cur = -1e18;
  if (i == n) sm = -1e18;
  pos = 0;
  int l2 = 0;
  for (; i < n; i++) {
    if (pos) {
      if (v[i] > 0) {
        cur = max(cur, v[i]);
      } else {
        sm += cur;
        cur = v[i];
        pos = 0;
        l2++;
      }
    } else {
      if (v[i] > 0) {
        sm += cur;
        cur = v[i];
        pos = 1;
        l2++;
      } else {
        cur = max(cur, v[i]);
      }
    }
  }
  sm += cur;
  if (l1 == l2)
    ans = max(ans, max(sm, sm1));
  else if (l1 > l2)
    ans = sm1;
  else
    ans = sm;
  cout << ans << endl;
}
int main() {
  fastio();
  int t;
  t = 1;
  cin >> t;
  for (int i = 1; i <= t; i++) {
    solve();
  }
  return 0;
}
