#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  int t;
  cin >> t;
  while (t--) {
    long long int n, a[200000], plusgreater = LLONG_MIN,
                                minusgreater = LLONG_MIN, sum = 0, baari, flag,
                                last;
    cin >> n;
    for (int i = 0; i < n; i++) cin >> a[i];
    if (a[0] > 0) {
      last = 1;
      plusgreater = a[0];
      baari = 0;
    } else {
      last = 0;
      minusgreater = a[0];
      baari = 1;
    }
    for (int i = 1; i < n; i++) {
      if (a[i] > 0 && baari == 1) {
        last = 1;
        sum += minusgreater;
        minusgreater = INT_MIN;
        if (a[i] > plusgreater) {
          plusgreater = a[i];
        }
        baari = 0;
      } else if (a[i] < 0 && baari == 0) {
        last = 0;
        sum += plusgreater;
        plusgreater = INT_MIN;
        if (a[i] > minusgreater) {
          minusgreater = a[i];
        }
        baari = 1;
      } else {
        if (a[i] > 0 && a[i] > plusgreater) {
          last = 1;
          plusgreater = a[i];
        }
        if (a[i] < 0 && a[i] > minusgreater) {
          last = 0;
          minusgreater = a[i];
        }
      }
    }
    if (last == 1 && plusgreater != LLONG_MIN)
      sum += plusgreater;
    else if (last == 0 && minusgreater != LLONG_MIN)
      sum += minusgreater;
    cout << sum << endl;
  }
}
