#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  cin >> t;
  while (t--) {
    int n;
    cin >> n;
    long long int arr[n];
    for (int i = 0; i < n; i++) {
      cin >> arr[i];
    }
    int i = 0;
    long long int sum = 0;
    long long int temp_max = 0;
    for (int k = 0; k < n; k++) {
      if (arr[k] < 0) {
        i = k;
        temp_max = arr[i];
        while (arr[i] < 0 && i < n) {
          if (temp_max < arr[i]) {
            temp_max = arr[i];
          }
          i++;
        }
      } else {
        i = k;
        temp_max = arr[i];
        while (arr[i] > 0 && i < n) {
          if (temp_max < arr[i]) {
            temp_max = arr[i];
          }
          i++;
        }
      }
      k = i - 1;
      sum = sum + temp_max;
    }
    cout << sum << endl;
  }
  return 0;
}
