#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long t;
  cin >> t;
  while (t--) {
    long long n = 0;
    cin >> n;
    long long sum = 0, state = 1, ma = LLONG_MIN, mi = LLONG_MIN, temp = 0;
    cin >> temp;
    if (temp < 0) {
      state = -1;
      mi = temp;
    } else {
      state = 1;
      ma = temp;
    }
    for (long long i = 1; i < n - 1; i++) {
      cin >> temp;
      if (temp > 0) {
        if (state == -1) {
          sum += mi;
        }
        state = 1;
        ma = max(ma, temp);
        mi = LLONG_MIN;
      }
      if (temp < 0) {
        if (state == 1) {
          sum += ma;
        }
        state = -1;
        mi = max(mi, temp);
        ma = LLONG_MIN;
      }
    }
    cin >> temp;
    if (temp < 0) {
      if (state == -1)
        sum += max(mi, temp);
      else
        sum += temp + ma;
    }
    if (temp > 0) {
      if (state == 1)
        sum += max(ma, temp);
      else
        sum += temp + mi;
    }
    cout << sum << "\n";
  }
  return 0;
}
