#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  cin >> t;
  while (t--) {
    long int n;
    cin >> n;
    long int arr[n];
    for (long int i = 0; i < n; i++) {
      cin >> arr[i];
    }
    vector<long int> as;
    long int maxi = arr[0];
    for (long int i = 0; i < n - 1; i++) {
      if (arr[i + 1] != 0 && arr[i] != 0) {
        if (arr[i + 1] * arr[i] < 0) {
          maxi = max(maxi, arr[i]);
          as.push_back(maxi);
          maxi = arr[i + 1];
        } else {
          maxi = max(maxi, arr[i]);
        }
      }
    }
    maxi = max(maxi, arr[n - 1]);
    as.push_back(maxi);
    long long int sumy = 0;
    long int r = as.size();
    long long int e = 0;
    for (long int i = 0; i < r; i++) {
      sumy = sumy + as[i];
    }
    cout << sumy << endl;
  }
}
