#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  cin >> t;
  for (int ii = 0; ii < t; ii++) {
    int n;
    cin >> n;
    vector<long long int> array;
    vector<long long int> seq;
    for (int jj = 0; jj < n; jj++) {
      long long int temp;
      cin >> temp;
      array.push_back(temp);
    }
    long int currentmax;
    int sign = 0;
    currentmax = array[0];
    if (array[0] > 0) sign = 1;
    for (int jj = 1; jj < n; jj++) {
      if (array[jj] < 0 && sign == 1) {
        seq.push_back(currentmax);
        currentmax = array[jj];
        sign = 0;
      } else if (array[jj] > 0 && sign == 0) {
        seq.push_back(currentmax);
        currentmax = array[jj];
        sign = 1;
      } else if (array[jj] < 0 && sign == 0) {
        if (array[jj] > currentmax) currentmax = array[jj];
      } else if (array[jj] > 0 && sign == 1) {
        if (array[jj] > currentmax) currentmax = array[jj];
      }
    }
    seq.push_back(currentmax);
    long long int sum = 0;
    cout << std::accumulate(seq.begin(), seq.end(), sum) << endl;
    seq.clear();
    array.clear();
  }
}
