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