#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  cin >> t;
  while (t--) {
    int n;
    cin >> n;
    int array[n];
    long long int total_sum;
    int largest_length = 1;
    for (int i = 0; i < n; i++) {
      cin >> array[i];
    }
    long long int i = 0;
    long long int j = 0;
    long long int sum = 0;
    while (i < n) {
      long long int maximum = array[i];
      j = i + 1;
      while (j < n && array[j] * array[j - 1] > 0) {
        if (array[j] > maximum) {
          maximum = array[j];
        }
        j += 1;
      }
      i = j;
      sum += maximum;
    }
    cout << sum << endl;
  }
  return 0;
}
