#include <bits/stdc++.h>
using namespace std;
bool sign(long long int x) { return x < 0; }
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];
    }
    long long int sum = 0;
    for (int i = 0; i < n; i++) {
      long long int x = arr[i];
      int j = i;
      while (j < n && sign(arr[i]) == sign(arr[j])) {
        x = max(arr[j], x);
        j++;
      }
      i = j - 1;
      sum += x;
    }
    printf("%lld \n", sum);
  }
}
