#include <bits/stdc++.h>
using namespace std;
long int sgn(long int k) {
  if (k < 0) {
    return -1;
  }
  return 1;
}
int main() {
  long int t;
  cin >> t;
  while (t--) {
    long int n;
    cin >> n;
    long int a[n];
    for (int i = 0; i < n; i++) {
      cin >> a[i];
    }
    long int s = 0;
    for (int i = 0; i < n; i++) {
      long int c = a[i];
      long int j = i;
      while (j < n && sgn(a[i]) == sgn(a[j])) {
        c = max(c, a[j]);
        j++;
      }
      s += c;
      i = j - 1;
    }
    cout << s << endl;
  }
  return 0;
}
