#include <bits/stdc++.h>
using namespace std;
const int N = 200001;
int t;
int n;
long long a[N];
int main() {
  cin >> t;
  while (t--) {
    long long sum = 0, mxpos = -1, mxneg = -1e9 - 1;
    scanf("%d", &n);
    for (int i = 0; i < n; i++) {
      scanf("%lld", &a[i]);
    }
    bool pos = a[0] > 0, neg = a[0] < 0;
    for (int i = 0; i < n; i++) {
      if (a[i] > 0) {
        mxpos = max(a[i], mxpos);
        if (neg) {
          sum += mxneg;
          neg = false;
          mxpos = a[i];
        }
        pos = true;
      }
      if (a[i] < 0) {
        mxneg = max(a[i], mxneg);
        if (pos) {
          sum += mxpos;
          pos = false;
          mxneg = a[i];
        }
        neg = true;
      }
    }
    if (pos)
      sum += mxpos;
    else
      sum += mxneg;
    printf("%lld\n", sum);
  }
}
