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